Skip to content

Commit d494433

Browse files
committed
Merge branch 'ds/maintenance-pack-refs'
"git maintenance" tool learned a new "pack-refs" maintenance task. * ds/maintenance-pack-refs: maintenance: incremental strategy runs pack-refs weekly maintenance: add pack-refs task
2 parents fdf3a27 + acc1c4d commit d494433

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

Documentation/config/maintenance.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ maintenance.strategy::
1515
* `none`: This default setting implies no task are run at any schedule.
1616
* `incremental`: This setting optimizes for performing small maintenance
1717
activities that do not delete any data. This does not schedule the `gc`
18-
task, but runs the `prefetch` and `commit-graph` tasks hourly and the
19-
`loose-objects` and `incremental-repack` tasks daily.
18+
task, but runs the `prefetch` and `commit-graph` tasks hourly, the
19+
`loose-objects` and `incremental-repack` tasks daily, and the `pack-refs`
20+
task weekly.
2021

2122
maintenance.<task>.enabled::
2223
This boolean config option controls whether the maintenance task

Documentation/git-maintenance.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ incremental-repack::
145145
which is a special case that attempts to repack all pack-files
146146
into a single pack-file.
147147

148+
pack-refs::
149+
The `pack-refs` task collects the loose reference files and
150+
collects them into a single file. This speeds up operations that
151+
need to iterate across many references. See linkgit:git-pack-refs[1]
152+
for more information.
153+
148154
OPTIONS
149155
-------
150156
--auto::

builtin/gc.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static const char *prune_worktrees_expire = "3.months.ago";
5454
static unsigned long big_pack_threshold;
5555
static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
5656

57-
static struct strvec pack_refs_cmd = STRVEC_INIT;
5857
static struct strvec reflog = STRVEC_INIT;
5958
static struct strvec repack = STRVEC_INIT;
6059
static struct strvec prune = STRVEC_INIT;
@@ -163,6 +162,15 @@ static void gc_config(void)
163162
git_config(git_default_config, NULL);
164163
}
165164

165+
struct maintenance_run_opts;
166+
static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *opts)
167+
{
168+
struct strvec pack_refs_cmd = STRVEC_INIT;
169+
strvec_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
170+
171+
return run_command_v_opt(pack_refs_cmd.v, RUN_GIT_CMD);
172+
}
173+
166174
static int too_many_loose_objects(void)
167175
{
168176
/*
@@ -518,8 +526,8 @@ static void gc_before_repack(void)
518526
if (done++)
519527
return;
520528

521-
if (pack_refs && run_command_v_opt(pack_refs_cmd.v, RUN_GIT_CMD))
522-
die(FAILED_RUN, pack_refs_cmd.v[0]);
529+
if (pack_refs && maintenance_task_pack_refs(NULL))
530+
die(FAILED_RUN, "pack-refs");
523531

524532
if (prune_reflogs && run_command_v_opt(reflog.v, RUN_GIT_CMD))
525533
die(FAILED_RUN, reflog.v[0]);
@@ -556,7 +564,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
556564
if (argc == 2 && !strcmp(argv[1], "-h"))
557565
usage_with_options(builtin_gc_usage, builtin_gc_options);
558566

559-
strvec_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
560567
strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
561568
strvec_pushl(&repack, "repack", "-d", "-l", NULL);
562569
strvec_pushl(&prune, "prune", "--expire", NULL);
@@ -1224,6 +1231,7 @@ enum maintenance_task_label {
12241231
TASK_INCREMENTAL_REPACK,
12251232
TASK_GC,
12261233
TASK_COMMIT_GRAPH,
1234+
TASK_PACK_REFS,
12271235

12281236
/* Leave as final value */
12291237
TASK__COUNT
@@ -1255,6 +1263,11 @@ static struct maintenance_task tasks[] = {
12551263
maintenance_task_commit_graph,
12561264
should_write_commit_graph,
12571265
},
1266+
[TASK_PACK_REFS] = {
1267+
"pack-refs",
1268+
maintenance_task_pack_refs,
1269+
NULL,
1270+
},
12581271
};
12591272

12601273
static int compare_tasks_by_selection(const void *a_, const void *b_)
@@ -1339,6 +1352,8 @@ static void initialize_maintenance_strategy(void)
13391352
tasks[TASK_INCREMENTAL_REPACK].schedule = SCHEDULE_DAILY;
13401353
tasks[TASK_LOOSE_OBJECTS].enabled = 1;
13411354
tasks[TASK_LOOSE_OBJECTS].schedule = SCHEDULE_DAILY;
1355+
tasks[TASK_PACK_REFS].enabled = 1;
1356+
tasks[TASK_PACK_REFS].schedule = SCHEDULE_WEEKLY;
13421357
}
13431358
}
13441359

t/t7900-maintenance.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,18 @@ test_expect_success 'maintenance.incremental-repack.auto' '
343343
test_subcommand git multi-pack-index write --no-progress <trace-B
344344
'
345345

346+
test_expect_success 'pack-refs task' '
347+
for n in $(test_seq 1 5)
348+
do
349+
git branch -f to-pack/$n HEAD || return 1
350+
done &&
351+
GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \
352+
git maintenance run --task=pack-refs &&
353+
ls .git/refs/heads/ >after &&
354+
test_must_be_empty after &&
355+
test_subcommand git pack-refs --all --prune <pack-refs.txt
356+
'
357+
346358
test_expect_success '--auto and --schedule incompatible' '
347359
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
348360
test_i18ngrep "at most one" err
@@ -396,18 +408,32 @@ test_expect_success 'maintenance.strategy inheritance' '
396408
git maintenance run --schedule=hourly --quiet &&
397409
GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
398410
git maintenance run --schedule=daily --quiet &&
411+
GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \
412+
git maintenance run --schedule=weekly --quiet &&
399413
400414
test_subcommand git commit-graph write --split --reachable \
401415
--no-progress <incremental-hourly.txt &&
402416
test_subcommand ! git prune-packed --quiet <incremental-hourly.txt &&
403417
test_subcommand ! git multi-pack-index write --no-progress \
404418
<incremental-hourly.txt &&
419+
test_subcommand ! git pack-refs --all --prune \
420+
<incremental-hourly.txt &&
405421
406422
test_subcommand git commit-graph write --split --reachable \
407423
--no-progress <incremental-daily.txt &&
408424
test_subcommand git prune-packed --quiet <incremental-daily.txt &&
409425
test_subcommand git multi-pack-index write --no-progress \
410426
<incremental-daily.txt &&
427+
test_subcommand ! git pack-refs --all --prune \
428+
<incremental-daily.txt &&
429+
430+
test_subcommand git commit-graph write --split --reachable \
431+
--no-progress <incremental-weekly.txt &&
432+
test_subcommand git prune-packed --quiet <incremental-weekly.txt &&
433+
test_subcommand git multi-pack-index write --no-progress \
434+
<incremental-weekly.txt &&
435+
test_subcommand git pack-refs --all --prune \
436+
<incremental-weekly.txt &&
411437
412438
# Modify defaults
413439
git config maintenance.commit-graph.schedule daily &&

0 commit comments

Comments
 (0)