@matheusbsbs / matheus-bagliano / commits / 0d7566a5ba
Fork 0

Add --aggressive option to 'git gc'

This option causes 'git gc' to more aggressively optimize the repository at the cost of taking much more wall clock and CPU time. Today this option causes git-pack-objects to use --no-use-delta option, and it allows the --window parameter to be set via the gc.aggressiveWindow configuration parameter. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Signed-off-by: Junio C Hamano <junkio@cox.net>

Theodore Tso committed May 9, 2007 at 15:48 UTC 0d7566a5baa9cc67fd3361b64bb48757e637fdb0
3 files changed +50 -3
Documentation/config.txt
+5
@@ -384,6 +384,11 @@ format.suffix::
384 `.patch`. Use this variable to change that suffix (make sure to
385 include the dot if you want it).
386
387 +gc.aggressiveWindow::
388 + The window size parameter used in the delta compression
389 + algorithm used by 'git gc --aggressive'. This defaults
390 + to 10.
391 +
392 gc.packrefs::
393 `git gc` does not run `git pack-refs` in a bare repository by
394 default so that older dumb-transport clients can still fetch
Documentation/git-gc.txt
+15 -1
@@ -8,7 +8,7 @@ git-gc - Cleanup unnecessary files and optimize the local repository
8
9 SYNOPSIS
10 --------
11 -'git-gc' [--prune]
11 +'git-gc' [--prune] [--aggressive]
12
13 DESCRIPTION
14 -----------
@@ -35,6 +35,13 @@ OPTIONS
35 repository at the same time (e.g. never use this option
36 in a cron script).
37
38 +--aggressive::
39 + Usually 'git-gc' runs very quickly while providing good disk
40 + space utilization and performance. This option will cause
41 + git-gc to more aggressive optimize the repository at the expense
42 + of taking much more time. The effects of this optimization are
43 + persistent, so this option only needs to be sporadically; every
44 + few hundred changesets or so.
45
46 Configuration
47 -------------
@@ -67,6 +74,13 @@ The optional configuration variable 'gc.packrefs' determines if
74 is not run in bare repositories by default, to allow older dumb-transport
75 clients fetch from the repository, but this will change in the future.
76
77 +The optional configuration variable 'gc.aggressiveWindow' controls how
78 +much time is spent optimizing the delta compression of the objects in
79 +the repository when the --aggressive option is specified. The larger
80 +the value, the more time is spent optimizing the delta compression. See
81 +the documentation for the --window' option in gitlink:git-repack[1] for
82 +more details. This defaults to 10.
83 +
84 See Also
85 --------
86 gitlink:git-prune[1]
builtin-gc.c
+30 -2
@@ -15,13 +15,15 @@
15
16 #define FAILED_RUN "failed to run %s"
17
18 -static const char builtin_gc_usage[] = "git-gc [--prune]";
18 +static const char builtin_gc_usage[] = "git-gc [--prune] [--aggressive]";
19
20 static int pack_refs = -1;
21 +static int aggressive_window = -1;
22
23 +#define MAX_ADD 10
24 static const char *argv_pack_refs[] = {"pack-refs", "--prune", NULL};
25 static const char *argv_reflog[] = {"reflog", "expire", "--all", NULL};
24 -static const char *argv_repack[] = {"repack", "-a", "-d", "-l", NULL};
26 +static const char *argv_repack[MAX_ADD] = {"repack", "-a", "-d", "-l", NULL};
27 static const char *argv_prune[] = {"prune", NULL};
28 static const char *argv_rerere[] = {"rerere", "gc", NULL};
29
@@ -34,13 +36,31 @@ static int gc_config(const char *var, const char *value)
36 pack_refs = git_config_bool(var, value);
37 return 0;
38 }
39 + if (!strcmp(var, "gc.aggressivewindow")) {
40 + aggressive_window = git_config_int(var, value);
41 + return 0;
42 + }
43 return git_default_config(var, value);
44 }
45
46 +static void append_option(const char **cmd, const char *opt, int max_length)
47 +{
48 + int i;
49 +
50 + for (i = 0; cmd[i]; i++)
51 + ;
52 +
53 + if (i + 2 >= max_length)
54 + die("Too many options specified");
55 + cmd[i++] = opt;
56 + cmd[i] = NULL;
57 +}
58 +
59 int cmd_gc(int argc, const char **argv, const char *prefix)
60 {
61 int i;
62 int prune = 0;
63 + char buf[80];
64
65 git_config(gc_config);
66
@@ -53,6 +73,14 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
73 prune = 1;
74 continue;
75 }
76 + if (!strcmp(arg, "--aggressive")) {
77 + append_option(argv_repack, "-f", MAX_ADD);
78 + if (aggressive_window > 0) {
79 + sprintf(buf, "--window=%d", aggressive_window);
80 + append_option(argv_repack, buf, MAX_ADD);
81 + }
82 + continue;
83 + }
84 /* perhaps other parameters later... */
85 break;
86 }