Skip to content

Commit cfe5eda

Browse files
Denton-Lgitster
authored andcommitted
t7700: consolidate code into test_has_duplicate_object()
The code to test that objects were not duplicated from the packfile was duplicated many times. Extract the duplicated code into test_has_duplicate_object() and use that instead. Refactor the resulting extraction so that if the git command fails, the return code is not silently lost. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ae475af commit cfe5eda

File tree

1 file changed

+23
-48
lines changed

1 file changed

+23
-48
lines changed

t/t7700-repack.sh

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ test_no_missing_in_packs () {
2121
test_must_be_empty missing
2222
}
2323

24+
# we expect $packsha1 and $objsha1 to be defined
25+
test_has_duplicate_object () {
26+
want_duplicate_object="$1"
27+
found_duplicate_object=false
28+
for p in .git/objects/pack/*.idx
29+
do
30+
idx=$(basename $p)
31+
test "pack-$packsha1.idx" = "$idx" && continue
32+
git verify-pack -v $p >packlist || return $?
33+
if egrep "^$objsha1" packlist
34+
then
35+
found_duplicate_object=true
36+
echo "DUPLICATE OBJECT FOUND"
37+
break
38+
fi
39+
done &&
40+
test "$want_duplicate_object" = "$found_duplicate_object"
41+
}
42+
2443
test_expect_success 'objects in packs marked .keep are not repacked' '
2544
echo content1 >file1 &&
2645
echo content2 >file2 &&
@@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
4059
mv pack-* .git/objects/pack/ &&
4160
git repack -A -d -l &&
4261
git prune-packed &&
43-
for p in .git/objects/pack/*.idx
44-
do
45-
idx=$(basename $p)
46-
test "pack-$packsha1.idx" = "$idx" && continue
47-
if git verify-pack -v $p | egrep "^$objsha1"
48-
then
49-
found_duplicate_object=1
50-
echo "DUPLICATE OBJECT FOUND"
51-
break
52-
fi
53-
done &&
54-
test -z "$found_duplicate_object"
62+
test_has_duplicate_object false
5563
'
5664

5765
test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
5866
# build on $objsha1, $packsha1, and .keep state from previous
5967
git repack -Adbl &&
60-
test_when_finished "found_duplicate_object=" &&
61-
for p in .git/objects/pack/*.idx
62-
do
63-
idx=$(basename $p)
64-
test "pack-$packsha1.idx" = "$idx" && continue
65-
if git verify-pack -v $p | egrep "^$objsha1"
66-
then
67-
found_duplicate_object=1
68-
echo "DUPLICATE OBJECT FOUND"
69-
break
70-
fi
71-
done &&
72-
test "$found_duplicate_object" = 1
68+
test_has_duplicate_object true
7369
'
7470

7571
test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
7672
# build on $objsha1, $packsha1, and .keep state from previous
7773
git -c repack.writebitmaps=true repack -Adl &&
78-
test_when_finished "found_duplicate_object=" &&
79-
for p in .git/objects/pack/*.idx
80-
do
81-
idx=$(basename $p)
82-
test "pack-$packsha1.idx" = "$idx" && continue
83-
if git verify-pack -v $p | egrep "^$objsha1"
84-
then
85-
found_duplicate_object=1
86-
echo "DUPLICATE OBJECT FOUND"
87-
break
88-
fi
89-
done &&
90-
test "$found_duplicate_object" = 1
74+
test_has_duplicate_object true
9175
'
9276

9377
test_expect_success 'loose objects in alternate ODB are not repacked' '
@@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
10084
git commit -m commit_file3 &&
10185
git repack -a -d -l &&
10286
git prune-packed &&
103-
for p in .git/objects/pack/*.idx
104-
do
105-
if git verify-pack -v $p | egrep "^$objsha1"
106-
then
107-
found_duplicate_object=1
108-
echo "DUPLICATE OBJECT FOUND"
109-
break
110-
fi
111-
done &&
112-
test -z "$found_duplicate_object"
87+
test_has_duplicate_object false
11388
'
11489

11590
test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '

0 commit comments

Comments
 (0)