Skip to content

Commit 9f673f9

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de0957c commit 9f673f9

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,10 @@ gc.autopacklimit::
11671167
--auto` consolidates them into one larger pack. The
11681168
default value is 50. Setting this to 0 disables it.
11691169

1170+
gc.autodetach::
1171+
Make `git gc --auto` return immediately andrun in background
1172+
if the system supports it. Default is true.
1173+
11701174
gc.packrefs::
11711175
Running `git pack-refs` in a repository renders it
11721176
unclonable by Git versions prior to 1.5.1.2 over dumb

builtin/gc.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static int pack_refs = 1;
2929
static int aggressive_window = 250;
3030
static int gc_auto_threshold = 6700;
3131
static int gc_auto_pack_limit = 50;
32+
static int detach_auto = 1;
3233
static const char *prune_expire = "2.weeks.ago";
3334

3435
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)
7374
gc_auto_pack_limit = git_config_int(var, value);
7475
return 0;
7576
}
77+
if (!strcmp(var, "gc.autodetach")) {
78+
detach_auto = git_config_bool(var, value);
79+
return 0;
80+
}
7681
if (!strcmp(var, "gc.pruneexpire")) {
7782
if (value && strcmp(value, "now")) {
7883
unsigned long now = approxidate("now");
@@ -301,11 +306,19 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
301306
*/
302307
if (!need_to_gc())
303308
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();
309322
} else
310323
add_repack_all_option();
311324

t/t5400-send-pack.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ test_expect_success 'receive-pack runs auto-gc in remote repo' '
164164
# Set the child to auto-pack if more than one pack exists
165165
cd child &&
166166
git config gc.autopacklimit 1 &&
167+
git config gc.autodetach false &&
167168
git branch test_auto_gc &&
168169
# And create a file that follows the temporary object naming
169170
# convention for the auto-gc to remove

0 commit comments

Comments
 (0)