Skip to content

Commit 6029cb0

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 050a45f commit 6029cb0

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Documentation/config/maintenance.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ maintenance.loose-objects.auto::
2121
positive value implies the command should run when the number of
2222
loose objects is at least the value of `maintenance.loose-objects.auto`.
2323
The default value is 100.
24+
25+
maintenance.incremental-repack.auto::
26+
This integer config option controls how often the `incremental-repack`
27+
task should be run as part of `git maintenance run --auto`. If zero,
28+
then the `incremental-repack` task will not run with the `--auto`
29+
option. A negative value will force the task to run every time.
30+
Otherwise, a positive value implies the command should run when the
31+
number of pack-files not in the multi-pack-index is at least the value
32+
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
@@ -31,6 +31,7 @@
3131
#include "refs.h"
3232
#include "remote.h"
3333
#include "midx.h"
34+
#include "object-store.h"
3435

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

@@ -1030,6 +1031,35 @@ static int maintenance_task_loose_objects(struct maintenance_opts *opts)
10301031
return prune_packed(opts) || pack_loose(opts);
10311032
}
10321033

1034+
static int incremental_repack_auto_condition(void)
1035+
{
1036+
struct packed_git *p;
1037+
int enabled;
1038+
int incremental_repack_auto_limit = 10;
1039+
int count = 0;
1040+
1041+
if (git_config_get_bool("core.multiPackIndex", &enabled) ||
1042+
!enabled)
1043+
return 0;
1044+
1045+
git_config_get_int("maintenance.incremental-repack.auto",
1046+
&incremental_repack_auto_limit);
1047+
1048+
if (!incremental_repack_auto_limit)
1049+
return 0;
1050+
if (incremental_repack_auto_limit < 0)
1051+
return 1;
1052+
1053+
for (p = get_packed_git(the_repository);
1054+
count < incremental_repack_auto_limit && p;
1055+
p = p->next) {
1056+
if (!p->multi_pack_index)
1057+
count++;
1058+
}
1059+
1060+
return count >= incremental_repack_auto_limit;
1061+
}
1062+
10331063
static int multi_pack_index_write(struct maintenance_opts *opts)
10341064
{
10351065
struct child_process child = CHILD_PROCESS_INIT;
@@ -1220,6 +1250,7 @@ static struct maintenance_task tasks[] = {
12201250
[TASK_INCREMENTAL_REPACK] = {
12211251
"incremental-repack",
12221252
maintenance_task_incremental_repack,
1253+
incremental_repack_auto_condition,
12231254
},
12241255
[TASK_GC] = {
12251256
"gc",

t/t7900-maintenance.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ test_expect_success 'incremental-repack task' '
187187
'
188188

189189
test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
190+
190191
for i in $(test_seq 1 5)
191192
do
192193
test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
@@ -217,4 +218,35 @@ test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
217218
--no-progress --batch-size=2147483647 <run-2g.txt
218219
'
219220

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

0 commit comments

Comments
 (0)