]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/maintenance: make "gc" strategy accessible
authorPatrick Steinhardt <ps@pks.im>
Fri, 24 Oct 2025 06:57:22 +0000 (08:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Oct 2025 20:42:44 +0000 (13:42 -0700)
While the user can pick the "incremental" maintenance strategy, it is
not possible to explicitly use the "gc" strategy. This has two
downsides:

  - It is impossible to use the default "gc" strategy for a specific
    repository when the strategy was globally set to a different strategy.

  - It is not possible to use git-gc(1) for scheduled maintenance.

Address these issues by making making the "gc" strategy configurable.
Furthermore, extend the strategy so that git-gc(1) runs for both manual
and scheduled maintenance.

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

index b7e90a71a3df4cac20a23f2969028a7220b6f11b..b2bacdc8220b3763d0c0ca9dfa1b8dc630da5b0b 100644 (file)
@@ -30,6 +30,8 @@ The possible strategies are:
 +
 * `none`: This strategy implies no tasks are run at all. This is the default
   strategy for scheduled maintenance.
+* `gc`: This strategy runs the `gc` task. This is the default strategy for
+  manual maintenance.
 * `incremental`: This setting optimizes for performing small maintenance
   activities that do not delete any data. This does not schedule the `gc`
   task, but runs the `prefetch` and `commit-graph` tasks hourly, the
index 3c0a9a2e5df64e90156baa1a4a7c35b89563eb97..8cab14500952577c37836d2e997b08a3e69950d8 100644 (file)
@@ -1843,10 +1843,11 @@ struct maintenance_strategy {
 
 static const struct maintenance_strategy none_strategy = { 0 };
 
-static const struct maintenance_strategy default_strategy = {
+static const struct maintenance_strategy gc_strategy = {
        .tasks = {
                [TASK_GC] = {
-                       .type = MAINTENANCE_TYPE_MANUAL,
+                       .type = MAINTENANCE_TYPE_MANUAL | MAINTENANCE_TYPE_SCHEDULED,
+                       .schedule = SCHEDULE_DAILY,
                },
        },
 };
@@ -1894,6 +1895,8 @@ static struct maintenance_strategy parse_maintenance_strategy(const char *name)
 {
        if (!strcasecmp(name, "incremental"))
                return incremental_strategy;
+       if (!strcasecmp(name, "gc"))
+               return gc_strategy;
        die(_("unknown maintenance strategy: '%s'"), name);
 }
 
@@ -1937,7 +1940,7 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
                strategy = none_strategy;
                type = MAINTENANCE_TYPE_SCHEDULED;
        } else {
-               strategy = default_strategy;
+               strategy = gc_strategy;
                type = MAINTENANCE_TYPE_MANUAL;
        }
 
index 5219bc17a69a0aefb3c3ab292147124b60ffe15e..85e0cea4d964114fc0e7bc19169afe09ed04dd64 100755 (executable)
@@ -915,7 +915,7 @@ test_expect_success 'maintenance.strategy is respected' '
                git gc --quiet --no-detach --skip-foreground-tasks
                EOF
 
-               test_strategy incremental --schedule=weekly <<-\EOF
+               test_strategy incremental --schedule=weekly <<-\EOF &&
                git pack-refs --all --prune
                git prune-packed --quiet
                git multi-pack-index write --no-progress
@@ -923,6 +923,18 @@ test_expect_success 'maintenance.strategy is respected' '
                git multi-pack-index repack --no-progress --batch-size=1
                git commit-graph write --split --reachable --no-progress
                EOF
+
+               test_strategy gc <<-\EOF &&
+               git pack-refs --all --prune
+               git reflog expire --all
+               git gc --quiet --no-detach --skip-foreground-tasks
+               EOF
+
+               test_strategy gc --schedule=weekly <<-\EOF
+               git pack-refs --all --prune
+               git reflog expire --all
+               git gc --quiet --no-detach --skip-foreground-tasks
+               EOF
        )
 '