gc: config option for running --auto in background
`gc --auto` takes time and can block the user temporarily (but not any less annoyingly). Make it run in background on systems that support it. The only thing lost with running in background is printouts. But gc output is not really interesting. You can keep it in foreground by changing gc.autodetach. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 8, 2014 at 14:08 UTC
9f673f9477c63433aa0774c11b9e42979721f4d6
3 files changed
+23
-5
Documentation/config.txt
+4
@@ -1167,6 +1167,10 @@ gc.autopacklimit::
1167
--auto` consolidates them into one larger pack. The
1168
default value is 50. Setting this to 0 disables it.
1169
1170
+gc.autodetach::
1171
+ Make `git gc --auto` return immediately andrun in background
1172
+ if the system supports it. Default is true.
1173
+
1174
gc.packrefs::
1175
Running `git pack-refs` in a repository renders it
1176
unclonable by Git versions prior to 1.5.1.2 over dumb
builtin/gc.c
+18
-5
@@ -29,6 +29,7 @@ static int pack_refs = 1;
29
static int aggressive_window = 250;
30
static int gc_auto_threshold = 6700;
31
static int gc_auto_pack_limit = 50;
32
+static int detach_auto = 1;
33
static const char *prune_expire = "2.weeks.ago";
34
35
static struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT;
@@ -73,6 +74,10 @@ static int gc_config(const char *var, const char *value, void *cb)
74
gc_auto_pack_limit = git_config_int(var, value);
75
return 0;
76
}
77
+ if (!strcmp(var, "gc.autodetach")) {
78
+ detach_auto = git_config_bool(var, value);
79
+ return 0;
80
+ }
81
if (!strcmp(var, "gc.pruneexpire")) {
82
if (value && strcmp(value, "now")) {
83
unsigned long now = approxidate("now");
@@ -301,11 +306,19 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
306
*/
307
if (!need_to_gc())
308
return 0;
304
- if (!quiet)
305
- fprintf(stderr,
306
- _("Auto packing the repository for optimum performance. You may also\n"
307
- "run \"git gc\" manually. See "
308
- "\"git help gc\" for more information.\n"));
309
+ if (!quiet) {
310
+ if (detach_auto)
311
+ fprintf(stderr, _("Auto packing the repository in background for optimum performance.\n"));
312
+ else
313
+ fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
314
+ fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
315
+ }
316
+ if (detach_auto)
317
+ /*
318
+ * failure to daemonize is ok, we'll continue
319
+ * in foreground
320
+ */
321
+ daemonize();
322
} else
323
add_repack_all_option();
324
t/t5400-send-pack.sh
+1
@@ -164,6 +164,7 @@ test_expect_success 'receive-pack runs auto-gc in remote repo' '
164
# Set the child to auto-pack if more than one pack exists
165
cd child &&
166
git config gc.autopacklimit 1 &&
167
+ git config gc.autodetach false &&
168
git branch test_auto_gc &&
169
# And create a file that follows the temporary object naming
170
# convention for the auto-gc to remove