1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/usr/bin/perl
# Copyright (C) 2018 The Qt Company Ltd.
# Copyright (C) 2019 Oswald Buddenhagen
# Contact: http://www.qt.io/licensing/
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.
#
use v5.14;
use strict;
use warnings;
no warnings qw(io);
our ($script, $script_path);
BEGIN {
use Cwd qw(abs_path);
if ($^O eq "msys") {
$0 =~ s,\\,/,g;
$0 =~ s,^(.):/,/$1/,g;
}
$script_path = $script = abs_path($0);
$script_path =~ s,/[^/]+$,,;
unshift @INC, $script_path;
}
use git_gpush;
sub usage()
{
print << "EOM";
Usage:
git gpull [<git-pull options>]
This command should be used instead of 'git pull --rebase'
when git-gpush is being used.
In addition to updating the local branch with upstream, it
will also call git-ggc at regular intervals (default 30 days,
configurable with gpush.gcInterval).
Copyright:
Copyright (C) 2018 The Qt Company Ltd.
Copyright (C) 2019 Oswald Buddenhagen
Contact: http://www.qt.io/licensing/
License:
You may use this file under the terms of the 3-clause BSD license.
EOM
}
while (@ARGV) {
my $arg = $ARGV[0];
if ($arg eq "--debug") {
$debug = 1;
shift @ARGV;
} elsif ($arg eq "-n" || $arg eq "--dry-run") {
$dry_run = 1;
shift @ARGV;
} elsif ($arg eq "-?" || $arg eq "--?" || $arg eq "-h" || $arg eq "--help") {
usage();
exit;
} else {
fail("Unrecognized command line argument '$arg'.\n");
}
}
goto_gitdir();
load_config();
my $gc_interval = git_config('gpush.gcInterval', 30);
if ($gc_interval != 0) {
load_state_file(); # No load_state(), and thus no load_refs().
my $next_gc = $last_gc + $gc_interval * 24 * 60 * 60;
if ($next_gc < time()) {
# It's seems backwards that we do this *before* pulling (which
# is likely to release more garbage), but chaining to the pull
# would be unreliable (the post-rewrite hook is not invoked when
# no local commits remain, and relying on the user to remember
# to use gpull instead of rebase with --continue is suboptimal).
# In the big picture the delay doesn't matter, as the gc interval
# is likely much bigger than the pull frequency anyway.
run_process(FWD_OUTPUT | DRY_RUN, $script_path."/git-ggc");
} else {
printf("Next gc date %d not reached yet (now is %d).\n", $next_gc, time())
if ($debug);
}
} else {
print "gpull auto-gc is disabled.\n" if ($debug);
}
exec("git", "pull", "--rebase", @ARGV) or fail("Cannot exec git: $!\n");
|