3 test_description
='pack-objects multi-pack reuse'
5 TEST_PASSES_SANITIZE_LEAK
=true
7 .
"$TEST_DIRECTORY"/lib-bitmap.sh
13 test_trace2_data pack-objects pack-reused
"$1"
16 test_packs_reused
() {
17 test_trace2_data pack-objects packs-reused
"$1"
21 # pack_position <object> </path/to/pack.idx
23 git show-index
>objects
&&
24 grep "$1" objects | cut
-d" " -f1
27 # test_pack_objects_reused_all <pack-reused> <packs-reused>
28 test_pack_objects_reused_all
() {
30 GIT_TRACE2_EVENT
="$PWD/trace2.txt" \
31 git pack-objects
--stdout --revs --all --delta-base-offset \
34 test_pack_reused
"$1" <trace2.txt
&&
35 test_packs_reused
"$2" <trace2.txt
38 # test_pack_objects_reused <pack-reused> <packs-reused>
39 test_pack_objects_reused
() {
41 GIT_TRACE2_EVENT
="$PWD/trace2.txt" \
42 git pack-objects
--stdout --revs >/dev
/null
&&
44 test_pack_reused
"$1" <trace2.txt
&&
45 test_packs_reused
"$2" <trace2.txt
48 test_expect_success
'preferred pack is reused for single-pack reuse' '
49 test_config pack.allowPackReuse single &&
54 git repack -d || return 1
57 git multi-pack-index write --bitmap &&
59 test_pack_objects_reused_all 3 1
62 test_expect_success
'multi-pack reuse is disabled by default' '
63 test_pack_objects_reused_all 3 1
66 test_expect_success
'feature.experimental implies multi-pack reuse' '
67 test_config feature.experimental true &&
69 test_pack_objects_reused_all 6 2
72 test_expect_success
'multi-pack reuse can be disabled with feature.experimental' '
73 test_config feature.experimental true &&
74 test_config pack.allowPackReuse single &&
76 test_pack_objects_reused_all 3 1
79 test_expect_success
'enable multi-pack reuse' '
80 git config pack.allowPackReuse multi
83 test_expect_success
'reuse all objects from subset of bitmapped packs' '
87 git multi-pack-index write --bitmap &&
94 test_pack_objects_reused 6 2 <in
97 test_expect_success
'reuse all objects from all packs' '
98 test_pack_objects_reused_all 9 3
101 test_expect_success
'reuse objects from first pack with middle gap' '
104 test_commit "$i" || return 1
107 # Set "pack.window" to zero to ensure that we do not create any
108 # deltas, which could alter the amount of pack reuse we perform
109 # (if, for e.g., we are not sending one or more bases).
110 D="$(git -c pack.window=0 pack-objects --all --unpacked $packdir/pack)" &&
112 d_pos="$(pack_position $(git rev-parse D) <$packdir/pack-$D.idx)" &&
113 e_pos="$(pack_position $(git rev-parse E) <$packdir/pack-$D.idx)" &&
114 f_pos="$(pack_position $(git rev-parse F) <$packdir/pack-$D.idx)" &&
116 # commits F, E, and D, should appear in that order at the
117 # beginning of the pack
118 test $f_pos -lt $e_pos &&
119 test $e_pos -lt $d_pos &&
121 # Ensure that the pack we are constructing sorts ahead of any
122 # other packs in lexical/bitmap order by choosing it as the
124 git multi-pack-index write --bitmap --preferred-pack="pack-$D.idx" &&
131 test_pack_objects_reused 3 1 <in
134 test_expect_success
'reuse objects from middle pack with middle gap' '
135 rm -fr $packdir/multi-pack-index* &&
137 # Ensure that the pack we are constructing sort into any
138 # position *but* the first one, by choosing a different pack as
140 git multi-pack-index write --bitmap --preferred-pack="pack-$A.idx" &&
147 test_pack_objects_reused 3 1 <in
150 test_expect_success
'omit delta with uninteresting base (same pack)' '
156 git commit -m "delta" &&
157 delta="$(git rev-parse HEAD)" &&
161 git commit -a -m "base" &&
162 base="$(git rev-parse HEAD)" &&
168 have_delta "$(git rev-parse $delta:f)" "$(git rev-parse $base:f)" &&
170 git multi-pack-index write --bitmap &&
173 $(git rev-parse other)
177 # We can only reuse the 3 objects corresponding to "other" from
180 # This is because even though we want "delta", we do not want
181 # "base", meaning that we have to inflate the delta/base-pair
182 # corresponding to the blob in commit "delta", which bypasses
183 # the pack-reuse mechanism.
185 # The remaining objects from the other pack are similarly not
186 # reused because their objects are on the uninteresting side of
188 test_pack_objects_reused 3 1 <in
191 test_expect_success
'omit delta from uninteresting base (cross pack)' '
193 $(git rev-parse $base)
194 ^$(git rev-parse $delta)
197 P="$(git pack-objects --revs $packdir/pack <in)" &&
199 git multi-pack-index write --bitmap --preferred-pack="pack-$P.idx" &&
201 packs_nr="$(find $packdir -type f -name "pack-*.pack" | wc -l)" &&
202 objects_nr="$(git rev-list --count --all --objects)" &&
204 test_pack_objects_reused_all $(($objects_nr - 1)) $packs_nr