Skip to content

Commit 29364f1

Browse files
pks-tgitster
authored andcommitted
run-command: honor "gc.auto" for auto-maintenance
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 a95ce12 (maintenance: replace run_auto_gc(), 2020-09-17), and with 1942d48 (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>
1 parent 6e95b07 commit 29364f1

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

run-command.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,10 +1944,14 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
19441944
int prepare_auto_maintenance(struct repository *r, int quiet,
19451945
struct child_process *maint)
19461946
{
1947-
int enabled, auto_detach;
1947+
int enabled = 1, auto_detach;
19481948

1949-
if (!repo_config_get_bool(r, "maintenance.auto", &enabled) &&
1950-
!enabled)
1949+
if (repo_config_get_bool(r, "maintenance.auto", &enabled)) {
1950+
int gc_threshold;
1951+
if (!repo_config_get_int(r, "gc.auto", &gc_threshold))
1952+
enabled = gc_threshold > 0;
1953+
}
1954+
if (!enabled)
19511955
return 0;
19521956

19531957
/*

t/t7900-maintenance.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ test_expect_success 'maintenance.auto config option' '
7373
test_subcommand ! git maintenance run --auto --quiet --detach <false
7474
'
7575

76+
test_expect_success 'gc.auto config option' '
77+
GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
78+
test_subcommand git maintenance run --auto --quiet --detach <default &&
79+
GIT_TRACE2_EVENT="$(pwd)/true" \
80+
git -c gc.auto=1 commit --quiet --allow-empty -m 2 &&
81+
test_subcommand git maintenance run --auto --quiet --detach <true &&
82+
GIT_TRACE2_EVENT="$(pwd)/false" \
83+
git -c gc.auto=0 commit --quiet --allow-empty -m 3 &&
84+
test_subcommand ! git maintenance run --auto --quiet --detach <false
85+
'
86+
87+
test_expect_success 'maintenance.auto overrides gc.auto' '
88+
test_when_finished "rm -f trace" &&
89+
90+
test_config maintenance.auto false &&
91+
test_config gc.auto 1 &&
92+
GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
93+
test_subcommand ! git maintenance run --auto --quiet --detach <trace &&
94+
95+
test_config maintenance.auto true &&
96+
test_config gc.auto 0 &&
97+
GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
98+
test_subcommand git maintenance run --auto --quiet --detach <trace
99+
'
100+
76101
for cfg in maintenance.autoDetach gc.autoDetach
77102
do
78103
test_expect_success "$cfg=true config option" '

0 commit comments

Comments
 (0)