Skip to content

Commit 1942d48

Browse files
derrickstoleegitster
authored andcommitted
maintenance: optionally skip --auto process
Some commands run 'git maintenance run --auto --[no-]quiet' after doing their normal work, as a way to keep repositories clean as they are used. Currently, users who do not want this maintenance to occur would set the 'gc.auto' config option to 0 to avoid the 'gc' task from running. However, this does not stop the extra process invocation. On Windows, this extra process invocation can be more expensive than necessary. Allow users to drop this extra process by setting 'maintenance.auto' to 'false'. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e841a79 commit 1942d48

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Documentation/config/maintenance.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
maintenance.auto::
2+
This boolean config option controls whether some commands run
3+
`git maintenance run --auto` after doing their normal work. Defaults
4+
to true.
5+
16
maintenance.<task>.enabled::
27
This boolean config option controls whether the maintenance task
38
with name `<task>` is run when no `--task` option is specified to

run-command.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "strbuf.h"
88
#include "string-list.h"
99
#include "quote.h"
10+
#include "config.h"
1011

1112
void child_process_init(struct child_process *child)
1213
{
@@ -1868,8 +1869,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
18681869

18691870
int run_auto_maintenance(int quiet)
18701871
{
1872+
int enabled;
18711873
struct child_process maint = CHILD_PROCESS_INIT;
18721874

1875+
if (!git_config_get_bool("maintenance.auto", &enabled) &&
1876+
!enabled)
1877+
return 0;
1878+
18731879
maint.git_cmd = 1;
18741880
strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL);
18751881
strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet");

t/t7900-maintenance.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ test_expect_success 'run [--auto|--quiet]' '
2828
test_subcommand git gc --no-quiet <run-no-quiet.txt
2929
'
3030

31+
test_expect_success 'maintenance.auto config option' '
32+
GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
33+
test_subcommand git maintenance run --auto --quiet <default &&
34+
GIT_TRACE2_EVENT="$(pwd)/true" \
35+
git -c maintenance.auto=true \
36+
commit --quiet --allow-empty -m 2 &&
37+
test_subcommand git maintenance run --auto --quiet <true &&
38+
GIT_TRACE2_EVENT="$(pwd)/false" \
39+
git -c maintenance.auto=false \
40+
commit --quiet --allow-empty -m 3 &&
41+
test_subcommand ! git maintenance run --auto --quiet <false
42+
'
43+
3144
test_expect_success 'maintenance.<task>.enabled' '
3245
git config maintenance.gc.enabled false &&
3346
git config maintenance.commit-graph.enabled true &&

0 commit comments

Comments
 (0)