Skip to content

Commit e841a79

Browse files
derrickstoleegitster
authored andcommitted
maintenance: add incremental-repack auto condition
The incremental-repack task updates the multi-pack-index by deleting pack- files that have been replaced with new packs, then repacking a batch of small pack-files into a larger pack-file. This incremental repack is faster than rewriting all object data, but is slower than some other maintenance activities. The 'maintenance.incremental-repack.auto' config option specifies how many pack-files should exist outside of the multi-pack-index before running the step. These pack-files could be created by 'git fetch' commands or by the loose-objects task. The default value is 10. Setting the option to zero disables the task with the '--auto' option, and a negative value makes the task run every time. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a13e3d0 commit e841a79

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Documentation/config/maintenance.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ maintenance.loose-objects.auto::
2323
positive value implies the command should run when the number of
2424
loose objects is at least the value of `maintenance.loose-objects.auto`.
2525
The default value is 100.
26+
27+
maintenance.incremental-repack.auto::
28+
This integer config option controls how often the `incremental-repack`
29+
task should be run as part of `git maintenance run --auto`. If zero,
30+
then the `incremental-repack` task will not run with the `--auto`
31+
option. A negative value will force the task to run every time.
32+
Otherwise, a positive value implies the command should run when the
33+
number of pack-files not in the multi-pack-index is at least the value
34+
of `maintenance.incremental-repack.auto`. The default value is 10.

builtin/gc.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "promisor-remote.h"
3131
#include "refs.h"
3232
#include "remote.h"
33+
#include "object-store.h"
3334

3435
#define FAILED_RUN "failed to run %s"
3536

@@ -1001,6 +1002,35 @@ static int maintenance_task_loose_objects(struct maintenance_run_opts *opts)
10011002
return prune_packed(opts) || pack_loose(opts);
10021003
}
10031004

1005+
static int incremental_repack_auto_condition(void)
1006+
{
1007+
struct packed_git *p;
1008+
int enabled;
1009+
int incremental_repack_auto_limit = 10;
1010+
int count = 0;
1011+
1012+
if (git_config_get_bool("core.multiPackIndex", &enabled) ||
1013+
!enabled)
1014+
return 0;
1015+
1016+
git_config_get_int("maintenance.incremental-repack.auto",
1017+
&incremental_repack_auto_limit);
1018+
1019+
if (!incremental_repack_auto_limit)
1020+
return 0;
1021+
if (incremental_repack_auto_limit < 0)
1022+
return 1;
1023+
1024+
for (p = get_packed_git(the_repository);
1025+
count < incremental_repack_auto_limit && p;
1026+
p = p->next) {
1027+
if (!p->multi_pack_index)
1028+
count++;
1029+
}
1030+
1031+
return count >= incremental_repack_auto_limit;
1032+
}
1033+
10041034
static int multi_pack_index_write(struct maintenance_run_opts *opts)
10051035
{
10061036
struct child_process child = CHILD_PROCESS_INIT;
@@ -1156,6 +1186,7 @@ static struct maintenance_task tasks[] = {
11561186
[TASK_INCREMENTAL_REPACK] = {
11571187
"incremental-repack",
11581188
maintenance_task_incremental_repack,
1189+
incremental_repack_auto_condition,
11591190
},
11601191
[TASK_GC] = {
11611192
"gc",

t/t7900-maintenance.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,32 @@ test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
219219
--no-progress --batch-size=2147483647 <run-2g.txt
220220
'
221221

222+
test_expect_success 'maintenance.incremental-repack.auto' '
223+
git repack -adk &&
224+
git config core.multiPackIndex true &&
225+
git multi-pack-index write &&
226+
GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
227+
-c maintenance.incremental-repack.auto=1 \
228+
maintenance run --auto --task=incremental-repack 2>/dev/null &&
229+
test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
230+
test_commit A &&
231+
git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
232+
HEAD
233+
^HEAD~1
234+
EOF
235+
GIT_TRACE2_EVENT=$(pwd)/trace-A git \
236+
-c maintenance.incremental-repack.auto=2 \
237+
maintenance run --auto --task=incremental-repack 2>/dev/null &&
238+
test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
239+
test_commit B &&
240+
git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
241+
HEAD
242+
^HEAD~1
243+
EOF
244+
GIT_TRACE2_EVENT=$(pwd)/trace-B git \
245+
-c maintenance.incremental-repack.auto=2 \
246+
maintenance run --auto --task=incremental-repack 2>/dev/null &&
247+
test_subcommand git multi-pack-index write --no-progress <trace-B
248+
'
249+
222250
test_done

0 commit comments

Comments
 (0)