Skip to content

Commit b62ad56

Browse files
ttaylorrgitster
authored andcommitted
midx.c: avoid cruft packs with non-zero repack --batch-size
Apply similar treatment with respect to cruft packs as in a few commits ago to `repack` with a non-zero `--batch-size`. Since the case of a non-zero `--batch-size` is handled separately (in `fill_included_packs_batch()` instead of `fill_included_packs_all()`), a separate fix must be applied for this case. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0a8e561 commit b62ad56

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

midx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,8 @@ static int fill_included_packs_batch(struct repository *r,
19461946
continue;
19471947
if (!pack_kept_objects && p->pack_keep)
19481948
continue;
1949+
if (p->is_cruft)
1950+
continue;
19491951
if (open_pack_index(p) || !p->num_objects)
19501952
continue;
19511953

t/t5319-multi-pack-index.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,47 @@ test_expect_success 'repack (all) ignores cruft pack' '
807807
)
808808
'
809809

810+
test_expect_success 'repack (--batch-size) ignores cruft pack' '
811+
git init repo &&
812+
test_when_finished "rm -fr repo" &&
813+
(
814+
cd repo &&
815+
816+
test_commit_bulk 5 &&
817+
test_commit --no-tag unreachable &&
818+
819+
git reset --hard HEAD^ &&
820+
git reflog expire --all --expire=all &&
821+
git repack --cruft -d &&
822+
823+
test_commit four &&
824+
825+
find $objdir/pack -type f -name "*.pack" | sort >before &&
826+
git repack -d &&
827+
find $objdir/pack -type f -name "*.pack" | sort >after &&
828+
829+
pack="$(comm -13 before after)" &&
830+
test_file_size "$pack" >sz &&
831+
# Set --batch-size to twice the size of the pack created
832+
# in the previous step, since this is enough to
833+
# accommodate it and the cruft pack.
834+
#
835+
# This means that the MIDX machinery *could* combine the
836+
# new and cruft packs together.
837+
#
838+
# We ensure that it does not below.
839+
batch="$((($(cat sz) * 2)))" &&
840+
841+
git multi-pack-index write &&
842+
843+
find $objdir/pack | sort >before &&
844+
git multi-pack-index repack --batch-size=$batch &&
845+
find $objdir/pack | sort >after &&
846+
847+
test_cmp before after
848+
)
849+
'
850+
810851
test_expect_success 'expire removes repacked packs' '
811852
(
812853
cd dup &&

0 commit comments

Comments
 (0)