Skip to content

Commit 65d655b

Browse files
derrickstoleegitster
authored andcommitted
maintenance: create maintenance.<task>.enabled config
Currently, a normal run of "git maintenance run" will only run the 'gc' task, as it is the only one enabled. This is mostly for backwards- compatible reasons since "git maintenance run --auto" commands replaced previous "git gc --auto" commands after some Git processes. Users could manually run specific maintenance tasks by calling "git maintenance run --task=<task>" directly. Allow users to customize which steps are run automatically using config. The 'maintenance.<task>.enabled' option then can turn on these other tasks (or turn off the 'gc' task). Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7514f6 commit 65d655b

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ include::config/mailinfo.txt[]
398398

399399
include::config/mailmap.txt[]
400400

401+
include::config/maintenance.txt[]
402+
401403
include::config/man.txt[]
402404

403405
include::config/merge.txt[]

Documentation/config/maintenance.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
maintenance.<task>.enabled::
2+
This boolean config option controls whether the maintenance task
3+
with name `<task>` is run when no `--task` option is specified to
4+
`git maintenance run`. These config values are ignored if a
5+
`--task` option exists. By default, only `maintenance.gc.enabled`
6+
is true.

Documentation/git-maintenance.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ SUBCOMMANDS
3030
-----------
3131

3232
run::
33-
Run one or more maintenance tasks. If one or more `--task=<task>`
34-
options are specified, then those tasks are run in the provided
35-
order. Otherwise, only the `gc` task is run.
33+
Run one or more maintenance tasks. If one or more `--task` options
34+
are specified, then those tasks are run in that order. Otherwise,
35+
the tasks are determined by which `maintenance.<task>.enabled`
36+
config options are true. By default, only `maintenance.gc.enabled`
37+
is true.
3638

3739
TASKS
3840
-----
@@ -67,8 +69,10 @@ OPTIONS
6769

6870
--task=<task>::
6971
If this option is specified one or more times, then only run the
70-
specified tasks in the specified order. See the 'TASKS' section
71-
for the list of accepted `<task>` values.
72+
specified tasks in the specified order. If no `--task=<task>`
73+
arguments are specified, then only the tasks with
74+
`maintenance.<task>.enabled` configured as `true` are considered.
75+
See the 'TASKS' section for the list of accepted `<task>` values.
7276

7377
GIT
7478
---

builtin/gc.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,24 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts)
841841
return result;
842842
}
843843

844+
static void initialize_task_config(void)
845+
{
846+
int i;
847+
struct strbuf config_name = STRBUF_INIT;
848+
for (i = 0; i < TASK__COUNT; i++) {
849+
int config_value;
850+
851+
strbuf_setlen(&config_name, 0);
852+
strbuf_addf(&config_name, "maintenance.%s.enabled",
853+
tasks[i].name);
854+
855+
if (!git_config_get_bool(config_name.buf, &config_value))
856+
tasks[i].enabled = config_value;
857+
}
858+
859+
strbuf_release(&config_name);
860+
}
861+
844862
static int task_option_parse(const struct option *opt,
845863
const char *arg, int unset)
846864
{
@@ -889,6 +907,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
889907
memset(&opts, 0, sizeof(opts));
890908

891909
opts.quiet = !isatty(2);
910+
initialize_task_config();
892911

893912
for (i = 0; i < TASK__COUNT; i++)
894913
tasks[i].selected_order = -1;

t/t7900-maintenance.sh

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

30+
test_expect_success 'maintenance.<task>.enabled' '
31+
git config maintenance.gc.enabled false &&
32+
git config maintenance.commit-graph.enabled true &&
33+
GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
34+
test_subcommand ! git gc --quiet <run-config.txt &&
35+
test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt
36+
'
37+
3038
test_expect_success 'run --task=<task>' '
3139
GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
3240
git maintenance run --task=commit-graph 2>/dev/null &&

0 commit comments

Comments
 (0)