From: Junio C Hamano Date: Mon, 16 Jun 2014 19:18:12 +0000 (-0700) Subject: Merge branch 'nd/daemonize-gc' X-Git-Tag: v2.1.0-rc0~115 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/1a81f6ceea7795e2b78cebd356d276afe79e7626?ds=inline;hp=-c Merge branch 'nd/daemonize-gc' "git gc --auto" was recently changed to run in the background to give control back early to the end-user sitting in front of the terminal, but it forgot that housekeeping involving reflogs should be done without other processes competing for accesses to the refs. * nd/daemonize-gc: gc --auto: do not lock refs in the background --- 1a81f6ceea7795e2b78cebd356d276afe79e7626 diff --combined builtin/gc.c index 85f5c2bc62,4588af70df..8d219d8c42 --- a/builtin/gc.c +++ b/builtin/gc.c @@@ -26,7 -26,7 +26,8 @@@ static const char * const builtin_gc_us }; static int pack_refs = 1; + static int prune_reflogs = 1; +static int aggressive_depth = 250; static int aggressive_window = 250; static int gc_auto_threshold = 6700; static int gc_auto_pack_limit = 50; @@@ -67,10 -67,6 +68,10 @@@ static int gc_config(const char *var, c aggressive_window = git_config_int(var, value); return 0; } + if (!strcmp(var, "gc.aggressivedepth")) { + aggressive_depth = git_config_int(var, value); + return 0; + } if (!strcmp(var, "gc.auto")) { gc_auto_threshold = git_config_int(var, value); return 0; @@@ -189,7 -185,7 +190,7 @@@ static int need_to_gc(void else if (!too_many_loose_objects()) return 0; - if (run_hook(NULL, "pre-auto-gc", NULL)) + if (run_hook_le(NULL, "pre-auto-gc", NULL)) return 0; return 1; } @@@ -198,12 -194,13 +199,12 @@@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) { static struct lock_file lock; - static char locking_host[128]; char my_host[128]; struct strbuf sb = STRBUF_INIT; struct stat st; uintmax_t pid; FILE *fp; - int fd, should_exit; + int fd; if (pidfile) /* already locked */ @@@ -215,8 -212,6 +216,8 @@@ fd = hold_lock_file_for_update(&lock, git_path("gc.pid"), LOCK_DIE_ON_ERROR); if (!force) { + static char locking_host[128]; + int should_exit; fp = fopen(git_path("gc.pid"), "r"); memset(locking_host, 0, sizeof(locking_host)); should_exit = @@@ -258,6 -253,19 +259,19 @@@ return NULL; } + static int gc_before_repack(void) + { + if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD)) + return error(FAILED_RUN, pack_refs_cmd.argv[0]); + + if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD)) + return error(FAILED_RUN, reflog.argv[0]); + + pack_refs = 0; + prune_reflogs = 0; + return 0; + } + int cmd_gc(int argc, const char **argv, const char *prefix) { int aggressive = 0; @@@ -299,8 -307,7 +313,8 @@@ if (aggressive) { argv_array_push(&repack, "-f"); - argv_array_push(&repack, "--depth=250"); + if (aggressive_depth > 0) + argv_array_pushf(&repack, "--depth=%d", aggressive_depth); if (aggressive_window > 0) argv_array_pushf(&repack, "--window=%d", aggressive_window); } @@@ -320,12 -327,15 +334,15 @@@ fprintf(stderr, _("Auto packing the repository for optimum performance.\n")); fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n")); } - if (detach_auto) + if (detach_auto) { + if (gc_before_repack()) + return -1; /* * failure to daemonize is ok, we'll continue * in foreground */ daemonize(); + } } else add_repack_all_option(); @@@ -337,11 -347,8 +354,8 @@@ name, (uintmax_t)pid); } - if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD)) - return error(FAILED_RUN, pack_refs_cmd.argv[0]); - - if (run_command_v_opt(reflog.argv, RUN_GIT_CMD)) - return error(FAILED_RUN, reflog.argv[0]); + if (gc_before_repack()) + return -1; if (run_command_v_opt(repack.argv, RUN_GIT_CMD)) return error(FAILED_RUN, repack.argv[0]);