refs: make refs/bisect/* per-worktree
[gitweb.git] / builtin / gc.c
index c41354b5121890134209115f91341ade91537986..0ad8d30b56f89a9ea6ac3a9ee5ae4593ae9754a0 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "tempfile.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "run-command.h"
@@ -42,20 +43,7 @@ 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 void remove_pidfile(void)
-{
-       if (pidfile)
-               unlink(pidfile);
-}
-
-static void remove_pidfile_on_signal(int signo)
-{
-       remove_pidfile();
-       sigchain_pop(signo);
-       raise(signo);
-}
+static struct tempfile pidfile;
 
 static void git_config_date_string(const char *key, const char **output)
 {
@@ -85,7 +73,7 @@ static void gc_config(void)
        git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
        git_config_get_bool("gc.autodetach", &detach_auto);
        git_config_date_string("gc.pruneexpire", &prune_expire);
-       git_config_date_string("gc.pruneworktreesexpire", &prune_worktrees_expire);
+       git_config_date_string("gc.worktreepruneexpire", &prune_worktrees_expire);
        git_config(git_default_config, NULL);
 }
 
@@ -201,7 +189,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
        int fd;
        char *pidfile_path;
 
-       if (pidfile)
+       if (is_tempfile_active(&pidfile))
                /* already locked */
                return NULL;
 
@@ -248,11 +236,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
        write_in_full(fd, sb.buf, sb.len);
        strbuf_release(&sb);
        commit_lock_file(&lock);
-
-       pidfile = pidfile_path;
-       sigchain_push_common(remove_pidfile_on_signal);
-       atexit(remove_pidfile);
-
+       register_tempfile(&pidfile, pidfile_path);
+       free(pidfile_path);
        return NULL;
 }
 
@@ -296,7 +281,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        argv_array_pushl(&reflog, "reflog", "expire", "--all", NULL);
        argv_array_pushl(&repack, "repack", "-d", "-l", NULL);
        argv_array_pushl(&prune, "prune", "--expire", NULL);
-       argv_array_pushl(&prune_worktrees, "prune", "--worktrees", "--expire", NULL);
+       argv_array_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL);
        argv_array_pushl(&rerere, "rerere", "gc", NULL);
 
        gc_config();