Merge branch 'jk/test-commit-bulk'
[gitweb.git] / builtin / gc.c
index 733bd7bdf463f2b59eaa7e029c6d964a55647247..c18efadda53e54f0e80dbd16737e2d40f47fa16f 100644 (file)
@@ -116,6 +116,19 @@ static void process_log_file_on_signal(int signo)
        raise(signo);
 }
 
+static int gc_config_is_timestamp_never(const char *var)
+{
+       const char *value;
+       timestamp_t expire;
+
+       if (!git_config_get_value(var, &value) && value) {
+               if (parse_expiry_date(value, &expire))
+                       die(_("failed to parse '%s' value '%s'"), var, value);
+               return expire == 0;
+       }
+       return 0;
+}
+
 static void gc_config(void)
 {
        const char *value;
@@ -127,6 +140,10 @@ static void gc_config(void)
                        pack_refs = git_config_bool("gc.packrefs", value);
        }
 
+       if (gc_config_is_timestamp_never("gc.reflogexpire") &&
+           gc_config_is_timestamp_never("gc.reflogexpireunreachable"))
+               prune_reflogs = 0;
+
        git_config_get_int("gc.aggressivewindow", &aggressive_window);
        git_config_get_int("gc.aggressivedepth", &aggressive_depth);
        git_config_get_int("gc.auto", &gc_auto_threshold);
@@ -489,14 +506,20 @@ static int report_last_gc_error(void)
 
 static void gc_before_repack(void)
 {
+       /*
+        * We may be called twice, as both the pre- and
+        * post-daemonized phases will call us, but running these
+        * commands more than once is pointless and wasteful.
+        */
+       static int done = 0;
+       if (done++)
+               return;
+
        if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
                die(FAILED_RUN, pack_refs_cmd.argv[0]);
 
        if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD))
                die(FAILED_RUN, reflog.argv[0]);
-
-       pack_refs = 0;
-       prune_reflogs = 0;
 }
 
 int cmd_gc(int argc, const char **argv, const char *prefix)
@@ -630,7 +653,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        gc_before_repack();
 
        if (!repository_format_precious_objects) {
-               close_all_packs(the_repository->objects);
+               close_object_store(the_repository->objects);
                if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
                        die(FAILED_RUN, repack.argv[0]);
 
@@ -658,13 +681,15 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        report_garbage = report_pack_garbage;
        reprepare_packed_git(the_repository);
        if (pack_garbage.nr > 0) {
-               close_all_packs(the_repository->objects);
+               close_object_store(the_repository->objects);
                clean_pack_garbage();
        }
 
-       if (gc_write_commit_graph)
-               write_commit_graph_reachable(get_object_directory(), 0,
-                                            !quiet && !daemonized);
+       if (gc_write_commit_graph &&
+           write_commit_graph_reachable(get_object_directory(),
+                                        !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0,
+                                        NULL))
+               return 1;
 
        if (auto_gc && too_many_loose_objects())
                warning(_("There are too many unreachable loose objects; "