Merge branch 'jk/gc-pre-detach-under-hook'
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Jul 2017 19:48:10 +0000 (12:48 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Jul 2017 19:48:10 +0000 (12:48 -0700)
We run an early part of "git gc" that deals with refs before
daemonising (and not under lock) even when running a background
auto-gc, which caused multiple gc processes attempting to run the
early part at the same time. This is now prevented by running the
early part also under the GC lock.

* jk/gc-pre-detach-under-hook:
gc: run pre-detach operations under lock

1  2 
builtin/gc.c
diff --combined builtin/gc.c
index 2ba50a28735eee23887211684e60aaeda81c3e98,2d2027d8b09913d30ce103c8c0ae4332fb729997..e6b84475aef6aeab05beda137fb2882f663fac0f
@@@ -11,7 -11,6 +11,7 @@@
   */
  
  #include "builtin.h"
 +#include "config.h"
  #include "tempfile.h"
  #include "lockfile.h"
  #include "parse-options.h"
@@@ -34,7 -33,7 +34,7 @@@ static int aggressive_window = 250
  static int gc_auto_threshold = 6700;
  static int gc_auto_pack_limit = 50;
  static int detach_auto = 1;
 -static unsigned long gc_log_expire_time;
 +static timestamp_t gc_log_expire_time;
  static const char *gc_log_expire = "1.day.ago";
  static const char *prune_expire = "2.weeks.ago";
  static const char *prune_worktrees_expire = "3.months.ago";
@@@ -149,7 -148,7 +149,7 @@@ static int too_many_loose_objects(void
        if (!dir)
                return 0;
  
 -      auto_threshold = (gc_auto_threshold + 255) / 256;
 +      auto_threshold = DIV_ROUND_UP(gc_auto_threshold, 256);
        while ((ent = readdir(dir)) != NULL) {
                if (strspn(ent->d_name, "0123456789abcdef") != 38 ||
                    ent->d_name[38] != '\0')
@@@ -414,8 -413,12 +414,12 @@@ int cmd_gc(int argc, const char **argv
                        if (report_last_gc_error())
                                return -1;
  
+                       if (lock_repo_for_gc(force, &pid))
+                               return 0;
                        if (gc_before_repack())
                                return -1;
+                       delete_tempfile(&pidfile);
                        /*
                         * failure to daemonize is ok, we'll continue
                         * in foreground