@matheusbsbs / matheus-bagliano / commits / 65d655b52d
Fork 0

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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Sep 17, 2020 at 18:11 UTC 65d655b52df3d4db0b4980f60106ed9785d025f8
5 files changed +44 -5
Documentation/config.txt
+2
@@ -398,6 +398,8 @@ include::config/mailinfo.txt[]
398
399 include::config/mailmap.txt[]
400
401 +include::config/maintenance.txt[]
402 +
403 include::config/man.txt[]
404
405 include::config/merge.txt[]
Documentation/config/maintenance.txt new
+6
@@ -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
+9 -5
@@ -30,9 +30,11 @@ SUBCOMMANDS
30 -----------
31
32 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.
38
39 TASKS
40 -----
@@ -67,8 +69,10 @@ OPTIONS
69
70 --task=<task>::
71 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.
76
77 GIT
78 ---
builtin/gc.c
+19
@@ -841,6 +841,24 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts)
841 return result;
842 }
843
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 +
862 static int task_option_parse(const struct option *opt,
863 const char *arg, int unset)
864 {
@@ -889,6 +907,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
907 memset(&opts, 0, sizeof(opts));
908
909 opts.quiet = !isatty(2);
910 + initialize_task_config();
911
912 for (i = 0; i < TASK__COUNT; i++)
913 tasks[i].selected_order = -1;
t/t7900-maintenance.sh
+8
@@ -27,6 +27,14 @@ test_expect_success 'run [--auto|--quiet]' '
27 test_subcommand git gc --no-quiet <run-no-quiet.txt
28 '
29
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 +
38 test_expect_success 'run --task=<task>' '
39 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
40 git maintenance run --task=commit-graph 2>/dev/null &&