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;
                    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;