OSDN Git Service

Merge branch 'nd/gc-auto-background-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 3 Nov 2015 23:32:33 +0000 (15:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Nov 2015 23:32:33 +0000 (15:32 -0800)
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

1  2 
builtin/gc.c

diff --cc 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);
 +      }
  }
  
 -      if (!fstat(log_lock.fd, &st) && st.st_size)
+ static void process_log_file(void)
+ {
+       struct stat st;
++      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);
        }
  
 -              dup2(log_lock.fd, 2);
+       if (daemonized) {
+               hold_lock_file_for_update(&log_lock,
+                                         git_path("gc.log"),
+                                         LOCK_DIE_ON_ERROR);
++              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;