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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Sep 19, 2022 at 21:55 UTC b62ad5681f7ff08065d172f541ab2578d7b38e18
2 files changed +43
midx.c
+2
@@ -1946,6 +1946,8 @@ static int fill_included_packs_batch(struct repository *r,
1946 continue;
1947 if (!pack_kept_objects && p->pack_keep)
1948 continue;
1949 + if (p->is_cruft)
1950 + continue;
1951 if (open_pack_index(p) || !p->num_objects)
1952 continue;
1953
t/t5319-multi-pack-index.sh
+41
@@ -807,6 +807,47 @@ test_expect_success 'repack (all) ignores cruft pack' '
807 )
808 '
809
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 +
851 test_expect_success 'expire removes repacked packs' '
852 (
853 cd dup &&