Skip to content

Commit 791170f

Browse files
ttaylorrgitster
authored andcommitted
t5326: move tests to t/lib-bitmap.sh
In t5326, we have a handful of tests that we would like to run twice: once using the MIDX's new `RIDX` chunk as the source of the reverse-index cache, and once using the separate `.rev` file. But because these tests mutate the state of the underlying repository, and then make assumptions about those mutations occurring in a certain sequence, simply running the tests twice in the same repository is awkward. Instead, extract the core of interesting tests into t/lib-bitmap.sh to prepare for them to be run twice, each in a separate test script. This means that they can each operate on a separate repository, removing any concerns about mutating state. For now, this patch is a strict cut-and-paste of some tests from t5326. The tests which did not move are not interesting with respect to the source of their reverse index data. Signed-off-by: Taylor Blau <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Reviewed-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f0ed59a commit 791170f

File tree

2 files changed

+179
-171
lines changed

2 files changed

+179
-171
lines changed

t/lib-bitmap.sh

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Helpers for scripts testing bitmap functionality; see t5310 for
22
# example usage.
33

4+
objdir=.git/objects
5+
midx=$objdir/pack/multi-pack-index
6+
47
# Compare a file containing rev-list bitmap traversal output to its non-bitmap
58
# counterpart. You can't just use test_cmp for this, because the two produce
69
# subtly different output:
@@ -264,3 +267,177 @@ have_delta () {
264267
midx_checksum () {
265268
test-tool read-midx --checksum "$1"
266269
}
270+
271+
# midx_pack_source <obj>
272+
midx_pack_source () {
273+
test-tool read-midx --show-objects .git/objects | grep "^$1 " | cut -f2
274+
}
275+
276+
test_rev_exists () {
277+
commit="$1"
278+
279+
test_expect_success 'reverse index exists' '
280+
GIT_TRACE2_EVENT=$(pwd)/event.trace \
281+
git rev-list --test-bitmap "$commit" &&
282+
283+
test_path_is_file $midx-$(midx_checksum $objdir).rev &&
284+
grep "\"category\":\"load_midx_revindex\",\"key\":\"source\",\"value\":\"rev\"" event.trace
285+
'
286+
}
287+
288+
midx_bitmap_core () {
289+
setup_bitmap_history
290+
291+
test_expect_success 'create single-pack midx with bitmaps' '
292+
git repack -ad &&
293+
git multi-pack-index write --bitmap &&
294+
test_path_is_file $midx &&
295+
test_path_is_file $midx-$(midx_checksum $objdir).bitmap
296+
'
297+
298+
test_rev_exists HEAD
299+
300+
basic_bitmap_tests
301+
302+
test_expect_success 'create new additional packs' '
303+
for i in $(test_seq 1 16)
304+
do
305+
test_commit "$i" &&
306+
git repack -d || return 1
307+
done &&
308+
309+
git checkout -b other2 HEAD~8 &&
310+
for i in $(test_seq 1 8)
311+
do
312+
test_commit "side-$i" &&
313+
git repack -d || return 1
314+
done &&
315+
git checkout second
316+
'
317+
318+
test_expect_success 'create multi-pack midx with bitmaps' '
319+
git multi-pack-index write --bitmap &&
320+
321+
ls $objdir/pack/pack-*.pack >packs &&
322+
test_line_count = 25 packs &&
323+
324+
test_path_is_file $midx &&
325+
test_path_is_file $midx-$(midx_checksum $objdir).bitmap
326+
'
327+
328+
test_rev_exists HEAD
329+
330+
basic_bitmap_tests
331+
332+
test_expect_success '--no-bitmap is respected when bitmaps exist' '
333+
git multi-pack-index write --bitmap &&
334+
335+
test_commit respect--no-bitmap &&
336+
git repack -d &&
337+
338+
test_path_is_file $midx &&
339+
test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
340+
341+
git multi-pack-index write --no-bitmap &&
342+
343+
test_path_is_file $midx &&
344+
test_path_is_missing $midx-$(midx_checksum $objdir).bitmap &&
345+
test_path_is_missing $midx-$(midx_checksum $objdir).rev
346+
'
347+
348+
test_expect_success 'setup midx with base from later pack' '
349+
# Write a and b so that "a" is a delta on top of base "b", since Git
350+
# prefers to delete contents out of a base rather than add to a shorter
351+
# object.
352+
test_seq 1 128 >a &&
353+
test_seq 1 130 >b &&
354+
355+
git add a b &&
356+
git commit -m "initial commit" &&
357+
358+
a=$(git rev-parse HEAD:a) &&
359+
b=$(git rev-parse HEAD:b) &&
360+
361+
# In the first pack, "a" is stored as a delta to "b".
362+
p1=$(git pack-objects .git/objects/pack/pack <<-EOF
363+
$a
364+
$b
365+
EOF
366+
) &&
367+
368+
# In the second pack, "a" is missing, and "b" is not a delta nor base to
369+
# any other object.
370+
p2=$(git pack-objects .git/objects/pack/pack <<-EOF
371+
$b
372+
$(git rev-parse HEAD)
373+
$(git rev-parse HEAD^{tree})
374+
EOF
375+
) &&
376+
377+
git prune-packed &&
378+
# Use the second pack as the preferred source, so that "b" occurs
379+
# earlier in the MIDX object order, rendering "a" unusable for pack
380+
# reuse.
381+
git multi-pack-index write --bitmap --preferred-pack=pack-$p2.idx &&
382+
383+
have_delta $a $b &&
384+
test $(midx_pack_source $a) != $(midx_pack_source $b)
385+
'
386+
387+
rev_list_tests 'full bitmap with backwards delta'
388+
389+
test_expect_success 'clone with bitmaps enabled' '
390+
git clone --no-local --bare . clone-reverse-delta.git &&
391+
test_when_finished "rm -fr clone-reverse-delta.git" &&
392+
393+
git rev-parse HEAD >expect &&
394+
git --git-dir=clone-reverse-delta.git rev-parse HEAD >actual &&
395+
test_cmp expect actual
396+
'
397+
398+
test_expect_success 'changing the preferred pack does not corrupt bitmaps' '
399+
rm -fr repo &&
400+
git init repo &&
401+
test_when_finished "rm -fr repo" &&
402+
(
403+
cd repo &&
404+
405+
test_commit A &&
406+
test_commit B &&
407+
408+
git rev-list --objects --no-object-names HEAD^ >A.objects &&
409+
git rev-list --objects --no-object-names HEAD^.. >B.objects &&
410+
411+
A=$(git pack-objects $objdir/pack/pack <A.objects) &&
412+
B=$(git pack-objects $objdir/pack/pack <B.objects) &&
413+
414+
cat >indexes <<-EOF &&
415+
pack-$A.idx
416+
pack-$B.idx
417+
EOF
418+
419+
git multi-pack-index write --bitmap --stdin-packs \
420+
--preferred-pack=pack-$A.pack <indexes &&
421+
git rev-list --test-bitmap A &&
422+
423+
git multi-pack-index write --bitmap --stdin-packs \
424+
--preferred-pack=pack-$B.pack <indexes &&
425+
git rev-list --test-bitmap A
426+
)
427+
'
428+
}
429+
430+
midx_bitmap_partial_tests () {
431+
test_expect_success 'setup partial bitmaps' '
432+
test_commit packed &&
433+
git repack &&
434+
test_commit loose &&
435+
git multi-pack-index write --bitmap 2>err &&
436+
test_path_is_file $midx &&
437+
test_path_is_file $midx-$(midx_checksum $objdir).bitmap
438+
'
439+
440+
test_rev_exists HEAD~
441+
442+
basic_bitmap_tests HEAD~
443+
}

t/t5326-multi-pack-bitmaps.sh

Lines changed: 2 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -9,134 +9,7 @@ test_description='exercise basic multi-pack bitmap functionality'
99
GIT_TEST_MULTI_PACK_INDEX=0
1010
GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
1111

12-
objdir=.git/objects
13-
midx=$objdir/pack/multi-pack-index
14-
15-
# midx_pack_source <obj>
16-
midx_pack_source () {
17-
test-tool read-midx --show-objects .git/objects | grep "^$1 " | cut -f2
18-
}
19-
20-
test_rev_exists () {
21-
commit="$1"
22-
23-
test_expect_success 'reverse index exists' '
24-
GIT_TRACE2_EVENT=$(pwd)/event.trace \
25-
git rev-list --test-bitmap "$commit" &&
26-
27-
test_path_is_file $midx-$(midx_checksum $objdir).rev &&
28-
grep "\"category\":\"load_midx_revindex\",\"key\":\"source\",\"value\":\"rev\"" event.trace
29-
'
30-
}
31-
32-
setup_bitmap_history
33-
34-
test_expect_success 'create single-pack midx with bitmaps' '
35-
git repack -ad &&
36-
git multi-pack-index write --bitmap &&
37-
test_path_is_file $midx &&
38-
test_path_is_file $midx-$(midx_checksum $objdir).bitmap
39-
'
40-
41-
test_rev_exists HEAD
42-
43-
basic_bitmap_tests
44-
45-
test_expect_success 'create new additional packs' '
46-
for i in $(test_seq 1 16)
47-
do
48-
test_commit "$i" &&
49-
git repack -d || return 1
50-
done &&
51-
52-
git checkout -b other2 HEAD~8 &&
53-
for i in $(test_seq 1 8)
54-
do
55-
test_commit "side-$i" &&
56-
git repack -d || return 1
57-
done &&
58-
git checkout second
59-
'
60-
61-
test_expect_success 'create multi-pack midx with bitmaps' '
62-
git multi-pack-index write --bitmap &&
63-
64-
ls $objdir/pack/pack-*.pack >packs &&
65-
test_line_count = 25 packs &&
66-
67-
test_path_is_file $midx &&
68-
test_path_is_file $midx-$(midx_checksum $objdir).bitmap
69-
'
70-
71-
test_rev_exists HEAD
72-
73-
basic_bitmap_tests
74-
75-
test_expect_success '--no-bitmap is respected when bitmaps exist' '
76-
git multi-pack-index write --bitmap &&
77-
78-
test_commit respect--no-bitmap &&
79-
git repack -d &&
80-
81-
test_path_is_file $midx &&
82-
test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
83-
84-
git multi-pack-index write --no-bitmap &&
85-
86-
test_path_is_file $midx &&
87-
test_path_is_missing $midx-$(midx_checksum $objdir).bitmap &&
88-
test_path_is_missing $midx-$(midx_checksum $objdir).rev
89-
'
90-
91-
test_expect_success 'setup midx with base from later pack' '
92-
# Write a and b so that "a" is a delta on top of base "b", since Git
93-
# prefers to delete contents out of a base rather than add to a shorter
94-
# object.
95-
test_seq 1 128 >a &&
96-
test_seq 1 130 >b &&
97-
98-
git add a b &&
99-
git commit -m "initial commit" &&
100-
101-
a=$(git rev-parse HEAD:a) &&
102-
b=$(git rev-parse HEAD:b) &&
103-
104-
# In the first pack, "a" is stored as a delta to "b".
105-
p1=$(git pack-objects .git/objects/pack/pack <<-EOF
106-
$a
107-
$b
108-
EOF
109-
) &&
110-
111-
# In the second pack, "a" is missing, and "b" is not a delta nor base to
112-
# any other object.
113-
p2=$(git pack-objects .git/objects/pack/pack <<-EOF
114-
$b
115-
$(git rev-parse HEAD)
116-
$(git rev-parse HEAD^{tree})
117-
EOF
118-
) &&
119-
120-
git prune-packed &&
121-
# Use the second pack as the preferred source, so that "b" occurs
122-
# earlier in the MIDX object order, rendering "a" unusable for pack
123-
# reuse.
124-
git multi-pack-index write --bitmap --preferred-pack=pack-$p2.idx &&
125-
126-
have_delta $a $b &&
127-
test $(midx_pack_source $a) != $(midx_pack_source $b)
128-
'
129-
130-
rev_list_tests 'full bitmap with backwards delta'
131-
132-
test_expect_success 'clone with bitmaps enabled' '
133-
git clone --no-local --bare . clone-reverse-delta.git &&
134-
test_when_finished "rm -fr clone-reverse-delta.git" &&
135-
136-
git rev-parse HEAD >expect &&
137-
git --git-dir=clone-reverse-delta.git rev-parse HEAD >actual &&
138-
test_cmp expect actual
139-
'
12+
midx_bitmap_core
14013

14114
bitmap_reuse_tests() {
14215
from=$1
@@ -213,18 +86,7 @@ test_expect_success 'missing object closure fails gracefully' '
21386
)
21487
'
21588

216-
test_expect_success 'setup partial bitmaps' '
217-
test_commit packed &&
218-
git repack &&
219-
test_commit loose &&
220-
git multi-pack-index write --bitmap 2>err &&
221-
test_path_is_file $midx &&
222-
test_path_is_file $midx-$(midx_checksum $objdir).bitmap
223-
'
224-
225-
test_rev_exists HEAD~
226-
227-
basic_bitmap_tests HEAD~
89+
midx_bitmap_partial_tests
22890

22991
test_expect_success 'removing a MIDX clears stale bitmaps' '
23092
rm -fr repo &&
@@ -398,35 +260,4 @@ test_expect_success 'hash-cache values are propagated from pack bitmaps' '
398260
)
399261
'
400262

401-
test_expect_success 'changing the preferred pack does not corrupt bitmaps' '
402-
rm -fr repo &&
403-
git init repo &&
404-
test_when_finished "rm -fr repo" &&
405-
(
406-
cd repo &&
407-
408-
test_commit A &&
409-
test_commit B &&
410-
411-
git rev-list --objects --no-object-names HEAD^ >A.objects &&
412-
git rev-list --objects --no-object-names HEAD^.. >B.objects &&
413-
414-
A=$(git pack-objects $objdir/pack/pack <A.objects) &&
415-
B=$(git pack-objects $objdir/pack/pack <B.objects) &&
416-
417-
cat >indexes <<-EOF &&
418-
pack-$A.idx
419-
pack-$B.idx
420-
EOF
421-
422-
git multi-pack-index write --bitmap --stdin-packs \
423-
--preferred-pack=pack-$A.pack <indexes &&
424-
git rev-list --test-bitmap A &&
425-
426-
git multi-pack-index write --bitmap --stdin-packs \
427-
--preferred-pack=pack-$B.pack <indexes &&
428-
git rev-list --test-bitmap A
429-
)
430-
'
431-
432263
test_done

0 commit comments

Comments
 (0)