Skip to content

Commit 40a7415

Browse files
pks-tgitster
authored andcommitted
builtin/maintenance: make "gc" strategy accessible
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 <[email protected]> Acked-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0e994d9 commit 40a7415

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Documentation/config/maintenance.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ The possible strategies are:
3030
+
3131
* `none`: This strategy implies no tasks are run at all. This is the default
3232
strategy for scheduled maintenance.
33+
* `gc`: This strategy runs the `gc` task. This is the default strategy for
34+
manual maintenance.
3335
* `incremental`: This setting optimizes for performing small maintenance
3436
activities that do not delete any data. This does not schedule the `gc`
3537
task, but runs the `prefetch` and `commit-graph` tasks hourly, the

builtin/gc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,10 +1843,11 @@ struct maintenance_strategy {
18431843

18441844
static const struct maintenance_strategy none_strategy = { 0 };
18451845

1846-
static const struct maintenance_strategy default_strategy = {
1846+
static const struct maintenance_strategy gc_strategy = {
18471847
.tasks = {
18481848
[TASK_GC] = {
1849-
.type = MAINTENANCE_TYPE_MANUAL,
1849+
.type = MAINTENANCE_TYPE_MANUAL | MAINTENANCE_TYPE_SCHEDULED,
1850+
.schedule = SCHEDULE_DAILY,
18501851
},
18511852
},
18521853
};
@@ -1894,6 +1895,8 @@ static struct maintenance_strategy parse_maintenance_strategy(const char *name)
18941895
{
18951896
if (!strcasecmp(name, "incremental"))
18961897
return incremental_strategy;
1898+
if (!strcasecmp(name, "gc"))
1899+
return gc_strategy;
18971900
die(_("unknown maintenance strategy: '%s'"), name);
18981901
}
18991902

@@ -1937,7 +1940,7 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
19371940
strategy = none_strategy;
19381941
type = MAINTENANCE_TYPE_SCHEDULED;
19391942
} else {
1940-
strategy = default_strategy;
1943+
strategy = gc_strategy;
19411944
type = MAINTENANCE_TYPE_MANUAL;
19421945
}
19431946

t/t7900-maintenance.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,14 +915,26 @@ test_expect_success 'maintenance.strategy is respected' '
915915
git gc --quiet --no-detach --skip-foreground-tasks
916916
EOF
917917
918-
test_strategy incremental --schedule=weekly <<-\EOF
918+
test_strategy incremental --schedule=weekly <<-\EOF &&
919919
git pack-refs --all --prune
920920
git prune-packed --quiet
921921
git multi-pack-index write --no-progress
922922
git multi-pack-index expire --no-progress
923923
git multi-pack-index repack --no-progress --batch-size=1
924924
git commit-graph write --split --reachable --no-progress
925925
EOF
926+
927+
test_strategy gc <<-\EOF &&
928+
git pack-refs --all --prune
929+
git reflog expire --all
930+
git gc --quiet --no-detach --skip-foreground-tasks
931+
EOF
932+
933+
test_strategy gc --schedule=weekly <<-\EOF
934+
git pack-refs --all --prune
935+
git reflog expire --all
936+
git gc --quiet --no-detach --skip-foreground-tasks
937+
EOF
926938
)
927939
'
928940

0 commit comments

Comments
 (0)