Skip to content

Commit ae475af

Browse files
Denton-Lgitster
authored andcommitted
t7700: consolidate code into test_no_missing_in_packs()
The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead. Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost. Instead of verifying each file of `alt_objects/pack/*.idx` individually in a for-loop, batch them together into one verification step. The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to extract the hash using sed or cut, sort the files, then use `comm -23` so that finding missing lines from the original file is done more efficiently. While we're at it, add a space to `commit_and_pack ()` for style. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 17a4ae9 commit ae475af

File tree

1 file changed

+15
-40
lines changed

1 file changed

+15
-40
lines changed

t/t7700-repack.sh

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@ test_description='git repack works correctly'
44

55
. ./test-lib.sh
66

7-
commit_and_pack() {
7+
commit_and_pack () {
88
test_commit "$@" 1>&2 &&
99
SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
1010
echo pack-${SHA1}.pack
1111
}
1212

13+
test_no_missing_in_packs () {
14+
myidx=$(ls -1 .git/objects/pack/*.idx) &&
15+
test_path_is_file "$myidx" &&
16+
git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
17+
sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig &&
18+
git verify-pack -v $myidx >dest.raw &&
19+
cut -d" " -f1 dest.raw | sort >dest &&
20+
comm -23 orig dest >missing &&
21+
test_must_be_empty missing
22+
}
23+
1324
test_expect_success 'objects in packs marked .keep are not repacked' '
1425
echo content1 >file1 &&
1526
echo content2 >file2 &&
@@ -105,19 +116,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is
105116
mkdir alt_objects/pack &&
106117
mv .git/objects/pack/* alt_objects/pack &&
107118
git repack -a &&
108-
myidx=$(ls -1 .git/objects/pack/*.idx) &&
109-
test_path_is_file "$myidx" &&
110-
for p in alt_objects/pack/*.idx
111-
do
112-
git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
113-
done | while read sha1 rest
114-
do
115-
if ! ( git verify-pack -v $myidx | grep "^$sha1" )
116-
then
117-
echo "Missing object in local pack: $sha1"
118-
return 1
119-
fi
120-
done
119+
test_no_missing_in_packs
121120
'
122121

123122
test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -128,19 +127,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
128127
git commit -m more_content &&
129128
git repack &&
130129
git repack -a -d &&
131-
myidx=$(ls -1 .git/objects/pack/*.idx) &&
132-
test_path_is_file "$myidx" &&
133-
for p in alt_objects/pack/*.idx
134-
do
135-
git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
136-
done | while read sha1 rest
137-
do
138-
if ! ( git verify-pack -v $myidx | grep "^$sha1" )
139-
then
140-
echo "Missing object in local pack: $sha1"
141-
return 1
142-
fi
143-
done
130+
test_no_missing_in_packs
144131
'
145132

146133
test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -156,19 +143,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
156143
fi
157144
done &&
158145
git repack -a -d &&
159-
myidx=$(ls -1 .git/objects/pack/*.idx) &&
160-
test_path_is_file "$myidx" &&
161-
for p in alt_objects/pack/*.idx
162-
do
163-
git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
164-
done | while read sha1 rest
165-
do
166-
if ! ( git verify-pack -v $myidx | grep "^$sha1" )
167-
then
168-
echo "Missing object in local pack: $sha1"
169-
return 1
170-
fi
171-
done
146+
test_no_missing_in_packs
172147
'
173148

174149
test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '

0 commit comments

Comments
 (0)