Merge branch 'nd/gc-lock-against-each-other'
authorJunio C Hamano <gitster@pobox.com>
Wed, 30 Oct 2013 19:10:27 +0000 (12:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Oct 2013 19:10:27 +0000 (12:10 -0700)
* nd/gc-lock-against-each-other:
gc: remove gc.pid file at end of execution

1  2 
builtin/gc.c
diff --combined builtin/gc.c
index 891a2c2ecb046dc29b2d9ce8b9d2982084bf9b19,dd910fbc374a067046670448815aaf790e1d629b..c14190f840b0427820ebf69b209d86f0a21c62b7
@@@ -14,6 -14,7 +14,7 @@@
  #include "cache.h"
  #include "parse-options.h"
  #include "run-command.h"
+ #include "sigchain.h"
  #include "argv-array.h"
  
  #define FAILED_RUN "failed to run %s"
@@@ -35,6 -36,21 +36,21 @@@ static struct argv_array repack = ARGV_
  static struct argv_array prune = ARGV_ARRAY_INIT;
  static struct argv_array rerere = ARGV_ARRAY_INIT;
  
+ static char *pidfile;
+ static void remove_pidfile(void)
+ {
+       if (pidfile)
+               unlink(pidfile);
+ }
+ static void remove_pidfile_on_signal(int signo)
+ {
+       remove_pidfile();
+       sigchain_pop(signo);
+       raise(signo);
+ }
  static int gc_config(const char *var, const char *value, void *cb)
  {
        if (!strcmp(var, "gc.packrefs")) {
@@@ -179,6 -195,10 +195,10 @@@ static const char *lock_repo_for_gc(in
        FILE *fp;
        int fd, should_exit;
  
+       if (pidfile)
+               /* already locked */
+               return NULL;
        if (gethostname(my_host, sizeof(my_host)))
                strcpy(my_host, "unknown");
  
        strbuf_release(&sb);
        commit_lock_file(&lock);
  
+       pidfile = git_pathdup("gc.pid");
+       sigchain_push_common(remove_pidfile_on_signal);
+       atexit(remove_pidfile);
        return NULL;
  }
  
@@@ -236,8 -260,8 +260,8 @@@ int cmd_gc(int argc, const char **argv
                { OPTION_STRING, 0, "prune", &prune_expire, N_("date"),
                        N_("prune unreferenced objects"),
                        PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire },
 -              OPT_BOOLEAN(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
 -              OPT_BOOLEAN(0, "auto", &auto_gc, N_("enable auto-gc mode")),
 +              OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
 +              OPT_BOOL(0, "auto", &auto_gc, N_("enable auto-gc mode")),
                OPT_BOOL(0, "force", &force, N_("force running gc even if there may be another gc running")),
                OPT_END()
        };