]> git.ipfire.org Git - thirdparty/git.git/commitdiff
run-command: honor "gc.auto" for auto-maintenance
authorPatrick Steinhardt <ps@pks.im>
Wed, 13 May 2026 07:31:14 +0000 (09:31 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 May 2026 07:57:54 +0000 (16:57 +0900)
The "gc.auto" configuration has traditionally been used to turn off
running git-gc(1) as part of our auto-maintenance. We have eventually
switched over to git-maintenance(1) in a95ce12430 (maintenance: replace
run_auto_gc(), 2020-09-17), and with 1942d48380 (maintenance: optionally
skip --auto process, 2020-08-28) we have introduced "maintenance.auto"
to control whether or not to run auto-maintenance.

At that point though we still shelled out to git-gc(1) internally. So
if "gc.auto=0" was set we would still _execute_ git-maintenance(1), but
the command would have exited fast because git-gc(1) itself knew to
honor the config key.

This has recently changed though, as we have adapted the default
maintenance strategy to not use git-gc(1) anymore. The consequence is
that "gc.auto=0" doesn't have an effect anymore, which is a somewhat
surprising change in behaviour for our users.

Adapt `run_auto_maintenance()` so that it knows to also read "gc.auto",
similar to how it also reads both "maintenance.autoDetach" and
"gc.autoDetach".

Reported-by: Jean-Christophe Manciot <actionmystique@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c
t/t7900-maintenance.sh

index c146a56532a1397fcafe769fac1968d01f912771..28202a81d83d8b495f90aff531ae770f50c21b03 100644 (file)
@@ -1944,10 +1944,14 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
 int prepare_auto_maintenance(struct repository *r, int quiet,
                             struct child_process *maint)
 {
-       int enabled, auto_detach;
+       int enabled = 1, auto_detach;
 
-       if (!repo_config_get_bool(r, "maintenance.auto", &enabled) &&
-           !enabled)
+       if (repo_config_get_bool(r, "maintenance.auto", &enabled)) {
+               int gc_threshold;
+               if (!repo_config_get_int(r, "gc.auto", &gc_threshold))
+                       enabled = gc_threshold > 0;
+       }
+       if (!enabled)
                return 0;
 
        /*
index df0bbc166929874abb895762d0d6949f5e80356a..97c8c701bbc911b2e3c0b332fc6dc0c5bd59b252 100755 (executable)
@@ -73,6 +73,31 @@ test_expect_success 'maintenance.auto config option' '
        test_subcommand ! git maintenance run --auto --quiet --detach <false
 '
 
+test_expect_success 'gc.auto config option' '
+       GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
+       test_subcommand git maintenance run --auto --quiet --detach <default &&
+       GIT_TRACE2_EVENT="$(pwd)/true" \
+               git -c gc.auto=1 commit --quiet --allow-empty -m 2 &&
+       test_subcommand git maintenance run --auto --quiet --detach <true &&
+       GIT_TRACE2_EVENT="$(pwd)/false" \
+               git -c gc.auto=0 commit --quiet --allow-empty -m 3 &&
+       test_subcommand ! git maintenance run --auto --quiet --detach <false
+'
+
+test_expect_success 'maintenance.auto overrides gc.auto' '
+       test_when_finished "rm -f trace" &&
+
+       test_config maintenance.auto false &&
+       test_config gc.auto 1 &&
+       GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
+       test_subcommand ! git maintenance run --auto --quiet --detach <trace &&
+
+       test_config maintenance.auto true &&
+       test_config gc.auto 0 &&
+       GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
+       test_subcommand git maintenance run --auto --quiet --detach <trace
+'
+
 for cfg in maintenance.autoDetach gc.autoDetach
 do
        test_expect_success "$cfg=true config option" '