]> git.ipfire.org Git - thirdparty/git.git/commitdiff
maintenance: create maintenance.<task>.enabled config
authorDerrick Stolee <dstolee@microsoft.com>
Thu, 17 Sep 2020 18:11:49 +0000 (18:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Sep 2020 18:30:05 +0000 (11:30 -0700)
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>
Documentation/config.txt
Documentation/config/maintenance.txt [new file with mode: 0644]
Documentation/git-maintenance.txt
builtin/gc.c
t/t7900-maintenance.sh

index 3042d80978d6158f827fa1ea272edb7d2b2d571b..f93b6837e4bd4c3abcb61f3e63e4f4b749794a98 100644 (file)
@@ -398,6 +398,8 @@ include::config/mailinfo.txt[]
 
 include::config/mailmap.txt[]
 
+include::config/maintenance.txt[]
+
 include::config/man.txt[]
 
 include::config/merge.txt[]
diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt
new file mode 100644 (file)
index 0000000..4402b8b
--- /dev/null
@@ -0,0 +1,6 @@
+maintenance.<task>.enabled::
+       This boolean config option controls whether the maintenance task
+       with name `<task>` is run when no `--task` option is specified to
+       `git maintenance run`. These config values are ignored if a
+       `--task` option exists. By default, only `maintenance.gc.enabled`
+       is true.
index 819ca41ab6aa1794fc0caed09a96a30d4cbf8d4a..6abcb8255a2bfdc908ac03960aece0cd1835a8fd 100644 (file)
@@ -30,9 +30,11 @@ SUBCOMMANDS
 -----------
 
 run::
-       Run one or more maintenance tasks. If one or more `--task=<task>`
-       options are specified, then those tasks are run in the provided
-       order. Otherwise, only the `gc` task is run.
+       Run one or more maintenance tasks. If one or more `--task` options
+       are specified, then those tasks are run in that order. Otherwise,
+       the tasks are determined by which `maintenance.<task>.enabled`
+       config options are true. By default, only `maintenance.gc.enabled`
+       is true.
 
 TASKS
 -----
@@ -67,8 +69,10 @@ OPTIONS
 
 --task=<task>::
        If this option is specified one or more times, then only run the
-       specified tasks in the specified order. See the 'TASKS' section
-       for the list of accepted `<task>` values.
+       specified tasks in the specified order. If no `--task=<task>`
+       arguments are specified, then only the tasks with
+       `maintenance.<task>.enabled` configured as `true` are considered.
+       See the 'TASKS' section for the list of accepted `<task>` values.
 
 GIT
 ---
index 7ba9c6f7c95c5a2af1842526bf56ee58128495f6..55a3d836f0a476531fa41fef977be91d2f52e64d 100644 (file)
@@ -841,6 +841,24 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts)
        return result;
 }
 
+static void initialize_task_config(void)
+{
+       int i;
+       struct strbuf config_name = STRBUF_INIT;
+       for (i = 0; i < TASK__COUNT; i++) {
+               int config_value;
+
+               strbuf_setlen(&config_name, 0);
+               strbuf_addf(&config_name, "maintenance.%s.enabled",
+                           tasks[i].name);
+
+               if (!git_config_get_bool(config_name.buf, &config_value))
+                       tasks[i].enabled = config_value;
+       }
+
+       strbuf_release(&config_name);
+}
+
 static int task_option_parse(const struct option *opt,
                             const char *arg, int unset)
 {
@@ -889,6 +907,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
        memset(&opts, 0, sizeof(opts));
 
        opts.quiet = !isatty(2);
+       initialize_task_config();
 
        for (i = 0; i < TASK__COUNT; i++)
                tasks[i].selected_order = -1;
index fb4cadd30c12201be145bd2aa5ed1a675fec06c2..8a162a18ba32fdc09403d65b5344bdd3d6d0df73 100755 (executable)
@@ -27,6 +27,14 @@ test_expect_success 'run [--auto|--quiet]' '
        test_subcommand git gc --no-quiet <run-no-quiet.txt
 '
 
+test_expect_success 'maintenance.<task>.enabled' '
+       git config maintenance.gc.enabled false &&
+       git config maintenance.commit-graph.enabled true &&
+       GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
+       test_subcommand ! git gc --quiet <run-config.txt &&
+       test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt
+'
+
 test_expect_success 'run --task=<task>' '
        GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
                git maintenance run --task=commit-graph 2>/dev/null &&