]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/maintenance: run maintenance tasks depending on type
authorPatrick Steinhardt <ps@pks.im>
Fri, 24 Oct 2025 06:57:20 +0000 (08:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Oct 2025 20:42:44 +0000 (13:42 -0700)
We basically have three different ways to execute repository
maintenance:

  1. Manual maintenance via `git maintenance run`.

  2. Automatic maintenance via `git maintenance run --auto`.

  3. Scheduled maintenance via `git maintenance run --schedule=`.

At the moment, maintenance strategies only have an effect for the last
type of maintenance. This is about to change in subsequent commits, but
to do so we need to be able to skip some tasks depending on how exactly
maintenance was invoked.

Introduce a new maintenance type that discern between manual (1 & 2) and
scheduled (3) maintenance. Convert the `enabled` field into a bitset so
that it becomes possible to specifiy which tasks exactly should run in a
specific context.

The types picked for existing strategies match the status quo:

  - The default strategy is only ever executed as part of a manual
    maintenance run. It is not possible to use it for scheduled
    maintenance.

  - The incremental strategy is only ever executed as part of a
    scheduled maintenance run. It is not possible to use it for manual
    maintenance.

The strategies will be tweaked in subsequent commits to make use of this
new infrastructure.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Acked-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c

index 0ba6e59de1400d6cfba20c6b2cb2d3b3ab772a9c..6cc4f98c7aa33c808c009215de461083f7d1529d 100644 (file)
@@ -1827,9 +1827,16 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
        return result;
 }
 
+enum maintenance_type {
+       /* As invoked via `git maintenance run --schedule=`. */
+       MAINTENANCE_TYPE_SCHEDULED = (1 << 0),
+       /* As invoked via `git maintenance run` and with `--auto`. */
+       MAINTENANCE_TYPE_MANUAL    = (1 << 1),
+};
+
 struct maintenance_strategy {
        struct {
-               int enabled;
+               unsigned type;
                enum schedule_priority schedule;
        } tasks[TASK__COUNT];
 };
@@ -1839,7 +1846,7 @@ static const struct maintenance_strategy none_strategy = { 0 };
 static const struct maintenance_strategy default_strategy = {
        .tasks = {
                [TASK_GC] = {
-                       .enabled = 1,
+                       .type = MAINTENANCE_TYPE_MANUAL,
                },
        },
 };
@@ -1847,23 +1854,23 @@ static const struct maintenance_strategy default_strategy = {
 static const struct maintenance_strategy incremental_strategy = {
        .tasks = {
                [TASK_COMMIT_GRAPH] = {
-                       .enabled = 1,
+                       .type = MAINTENANCE_TYPE_SCHEDULED,
                        .schedule = SCHEDULE_HOURLY,
                },
                [TASK_PREFETCH] = {
-                       .enabled = 1,
+                       .type = MAINTENANCE_TYPE_SCHEDULED,
                        .schedule = SCHEDULE_HOURLY,
                },
                [TASK_INCREMENTAL_REPACK] = {
-                       .enabled = 1,
+                       .type = MAINTENANCE_TYPE_SCHEDULED,
                        .schedule = SCHEDULE_DAILY,
                },
                [TASK_LOOSE_OBJECTS] = {
-                       .enabled = 1,
+                       .type = MAINTENANCE_TYPE_SCHEDULED,
                        .schedule = SCHEDULE_DAILY,
                },
                [TASK_PACK_REFS] = {
-                       .enabled = 1,
+                       .type = MAINTENANCE_TYPE_SCHEDULED,
                        .schedule = SCHEDULE_WEEKLY,
                },
        },
@@ -1881,6 +1888,7 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
 {
        struct strbuf config_name = STRBUF_INIT;
        struct maintenance_strategy strategy;
+       enum maintenance_type type;
        const char *config_str;
 
        /*
@@ -1915,8 +1923,10 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
                        strategy = parse_maintenance_strategy(config_str);
                else
                        strategy = none_strategy;
+               type = MAINTENANCE_TYPE_SCHEDULED;
        } else {
                strategy = default_strategy;
+               type = MAINTENANCE_TYPE_MANUAL;
        }
 
        for (size_t i = 0; i < TASK__COUNT; i++) {
@@ -1926,8 +1936,8 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
                strbuf_addf(&config_name, "maintenance.%s.enabled",
                            tasks[i].name);
                if (!repo_config_get_bool(the_repository, config_name.buf, &config_value))
-                       strategy.tasks[i].enabled = config_value;
-               if (!strategy.tasks[i].enabled)
+                       strategy.tasks[i].type = config_value ? type : 0;
+               if (!(strategy.tasks[i].type & type))
                        continue;
 
                if (opts->schedule) {