From: Junio C Hamano Date: Thu, 15 Oct 2015 22:43:32 +0000 (-0700) Subject: Merge branch 'nd/gc-auto-background-fix' X-Git-Tag: v2.7.0-rc0~114 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/076c8278583b70547c1c5a65941a661f08210252 Merge branch 'nd/gc-auto-background-fix' When "git gc --auto" is backgrounded, its diagnosis message is lost. Save it to a file in $GIT_DIR and show it next time the "gc --auto" is run. * nd/gc-auto-background-fix: gc: save log from daemonized gc --auto and print it next time --- 076c8278583b70547c1c5a65941a661f08210252 diff --cc builtin/gc.c index 0ad8d30b56,47fc1a6547..9ff0204940 --- a/builtin/gc.c +++ b/builtin/gc.c @@@ -40,22 -38,46 +40,45 @@@ static struct argv_array pack_refs_cmd static struct argv_array reflog = ARGV_ARRAY_INIT; static struct argv_array repack = ARGV_ARRAY_INIT; static struct argv_array prune = ARGV_ARRAY_INIT; +static struct argv_array prune_worktrees = ARGV_ARRAY_INIT; static struct argv_array rerere = ARGV_ARRAY_INIT; -static char *pidfile; +static struct tempfile pidfile; + static struct lock_file log_lock; -static void remove_pidfile(void) +static void git_config_date_string(const char *key, const char **output) { - if (pidfile) - unlink(pidfile); -} - -static void remove_pidfile_on_signal(int signo) -{ - remove_pidfile(); - sigchain_pop(signo); - raise(signo); + if (git_config_get_string_const(key, output)) + return; + if (strcmp(*output, "now")) { + unsigned long now = approxidate("now"); + if (approxidate(*output) >= now) + git_die_config(key, _("Invalid %s: '%s'"), key, *output); + } } + static void process_log_file(void) + { + struct stat st; - if (!fstat(log_lock.fd, &st) && st.st_size) ++ if (!fstat(get_lock_file_fd(&log_lock), &st) && st.st_size) + commit_lock_file(&log_lock); + else + rollback_lock_file(&log_lock); + } + + static void process_log_file_at_exit(void) + { + fflush(stderr); + process_log_file(); + } + + static void process_log_file_on_signal(int signo) + { + process_log_file(); + sigchain_pop(signo); + raise(signo); + } + static void gc_config(void) { const char *value; @@@ -337,6 -388,15 +382,15 @@@ int cmd_gc(int argc, const char **argv name, (uintmax_t)pid); } + if (daemonized) { + hold_lock_file_for_update(&log_lock, + git_path("gc.log"), + LOCK_DIE_ON_ERROR); - dup2(log_lock.fd, 2); ++ dup2(get_lock_file_fd(&log_lock), 2); + sigchain_push_common(process_log_file_on_signal); + atexit(process_log_file_at_exit); + } + if (gc_before_repack()) return -1;