t5332-multi-pack-reuse.sh: extract pack-objects helper functions

Most of the tests in t5332 perform some setup before repeating a common refrain that looks like: : >trace2.txt && GIT_TRACE2_EVENT="$PWD/trace2.txt" \ git pack-objects --stdout --revs --all >/dev/null && test_pack_reused $objects_nr <trace2.txt && test_packs_reused $packs_nr <trace2.txt The next commit will add more tests which repeat the above refrain. Avoid duplicating this invocation even further and prepare for the following commit by wrapping the above in a helper function called `test_pack_objects_reused_all()`. Introduce another similar function `test_pack_objects_reused`, which expects to read a list of revisions over stdin for tests which need more fine-grained control of the contents of the pack they generate. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Feb 5, 2024 at 17:50 UTC 7c01878eeb15e8dd75f0262bdfb3249c85a30a4a
1 file changed +29 -42
t/t5332-multi-pack-reuse.sh
+29 -42
@@ -23,6 +23,27 @@ pack_position () {
23 grep "$1" objects | cut -d" " -f1
24 }
25
26 +# test_pack_objects_reused_all <pack-reused> <packs-reused>
27 +test_pack_objects_reused_all () {
28 + : >trace2.txt &&
29 + GIT_TRACE2_EVENT="$PWD/trace2.txt" \
30 + git pack-objects --stdout --revs --all --delta-base-offset \
31 + >/dev/null &&
32 +
33 + test_pack_reused "$1" <trace2.txt &&
34 + test_packs_reused "$2" <trace2.txt
35 +}
36 +
37 +# test_pack_objects_reused <pack-reused> <packs-reused>
38 +test_pack_objects_reused () {
39 + : >trace2.txt &&
40 + GIT_TRACE2_EVENT="$PWD/trace2.txt" \
41 + git pack-objects --stdout --revs >/dev/null &&
42 +
43 + test_pack_reused "$1" <trace2.txt &&
44 + test_packs_reused "$2" <trace2.txt
45 +}
46 +
47 test_expect_success 'preferred pack is reused for single-pack reuse' '
48 test_config pack.allowPackReuse single &&
49
@@ -34,14 +55,10 @@ test_expect_success 'preferred pack is reused for single-pack reuse' '
55
56 git multi-pack-index write --bitmap &&
57
37 - : >trace2.txt &&
38 - GIT_TRACE2_EVENT="$PWD/trace2.txt" \
39 - git pack-objects --stdout --revs --all >/dev/null &&
40 -
41 - test_pack_reused 3 <trace2.txt &&
42 - test_packs_reused 1 <trace2.txt
58 + test_pack_objects_reused_all 3 1
59 '
60
61 +
62 test_expect_success 'enable multi-pack reuse' '
63 git config pack.allowPackReuse multi
64 '
@@ -57,21 +74,11 @@ test_expect_success 'reuse all objects from subset of bitmapped packs' '
74 ^$(git rev-parse A)
75 EOF
76
60 - : >trace2.txt &&
61 - GIT_TRACE2_EVENT="$PWD/trace2.txt" \
62 - git pack-objects --stdout --revs <in >/dev/null &&
63 -
64 - test_pack_reused 6 <trace2.txt &&
65 - test_packs_reused 2 <trace2.txt
77 + test_pack_objects_reused 6 2 <in
78 '
79
80 test_expect_success 'reuse all objects from all packs' '
69 - : >trace2.txt &&
70 - GIT_TRACE2_EVENT="$PWD/trace2.txt" \
71 - git pack-objects --stdout --revs --all >/dev/null &&
72 -
73 - test_pack_reused 9 <trace2.txt &&
74 - test_packs_reused 3 <trace2.txt
81 + test_pack_objects_reused_all 9 3
82 '
83
84 test_expect_success 'reuse objects from first pack with middle gap' '
@@ -104,12 +111,7 @@ test_expect_success 'reuse objects from first pack with middle gap' '
111 ^$(git rev-parse D)
112 EOF
113
107 - : >trace2.txt &&
108 - GIT_TRACE2_EVENT="$PWD/trace2.txt" \
109 - git pack-objects --stdout --delta-base-offset --revs <in >/dev/null &&
110 -
111 - test_pack_reused 3 <trace2.txt &&
112 - test_packs_reused 1 <trace2.txt
114 + test_pack_objects_reused 3 1 <in
115 '
116
117 test_expect_success 'reuse objects from middle pack with middle gap' '
@@ -125,12 +127,7 @@ test_expect_success 'reuse objects from middle pack with middle gap' '
127 ^$(git rev-parse D)
128 EOF
129
128 - : >trace2.txt &&
129 - GIT_TRACE2_EVENT="$PWD/trace2.txt" \
130 - git pack-objects --stdout --delta-base-offset --revs <in >/dev/null &&
131 -
132 - test_pack_reused 3 <trace2.txt &&
133 - test_packs_reused 1 <trace2.txt
130 + test_pack_objects_reused 3 1 <in
131 '
132
133 test_expect_success 'omit delta with uninteresting base (same pack)' '
@@ -160,10 +157,6 @@ test_expect_success 'omit delta with uninteresting base (same pack)' '
157 ^$base
158 EOF
159
163 - : >trace2.txt &&
164 - GIT_TRACE2_EVENT="$PWD/trace2.txt" \
165 - git pack-objects --stdout --delta-base-offset --revs <in >/dev/null &&
166 -
160 # We can only reuse the 3 objects corresponding to "other" from
161 # the latest pack.
162 #
@@ -175,8 +168,7 @@ test_expect_success 'omit delta with uninteresting base (same pack)' '
168 # The remaining objects from the other pack are similarly not
169 # reused because their objects are on the uninteresting side of
170 # the query.
178 - test_pack_reused 3 <trace2.txt &&
179 - test_packs_reused 1 <trace2.txt
171 + test_pack_objects_reused 3 1 <in
172 '
173
174 test_expect_success 'omit delta from uninteresting base (cross pack)' '
@@ -189,15 +181,10 @@ test_expect_success 'omit delta from uninteresting base (cross pack)' '
181
182 git multi-pack-index write --bitmap --preferred-pack="pack-$P.idx" &&
183
192 - : >trace2.txt &&
193 - GIT_TRACE2_EVENT="$PWD/trace2.txt" \
194 - git pack-objects --stdout --delta-base-offset --all >/dev/null &&
195 -
184 packs_nr="$(find $packdir -type f -name "pack-*.pack" | wc -l)" &&
185 objects_nr="$(git rev-list --count --all --objects)" &&
186
199 - test_pack_reused $(($objects_nr - 1)) <trace2.txt &&
200 - test_packs_reused $packs_nr <trace2.txt
187 + test_pack_objects_reused_all $(($objects_nr - 1)) $packs_nr
188 '
189
190 test_done