t7700: make references to SHA-1 generic
Make the test more hash-agnostic by renaming variables from "sha1" to some variation of "oid" or "packid". Also, replace the regex, `[0-9a-f]\{40\}` with `$OID_REGEX`. A better name for "incrpackid" (incremental pack-id) might have been just "packid". However, later in the test suite, we have other uses of "packid". Although the scopes of these variables don't conflict, a future developer may think that commit_and_pack() and test_has_duplicate_object() are semantically related somehow since they share the same variable name. Give them distinct names so that it's clear these uses are unrelated. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Denton Liu committed
Dec 4, 2019 at 14:03 UTC
3699d69df0345309ba16b9c7fb43fd86a7595f58
1 file changed
+19
-19
t/t7700-repack.sh
+19
-19
@@ -6,31 +6,31 @@ test_description='git repack works correctly'
6
7
commit_and_pack () {
8
test_commit "$@" 1>&2 &&
9
- SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
10
- echo pack-${SHA1}.pack
9
+ incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
10
+ echo pack-${incrpackid}.pack
11
}
12
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 &&
17
+ sed -n -e "s/^\($OID_REGEX\).*/\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
24
-# we expect $packsha1 and $objsha1 to be defined
24
+# we expect $packid and $oid 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
31
+ test "pack-$packid.idx" = "$idx" && continue
32
git verify-pack -v $p >packlist || return $?
33
- if grep "^$objsha1" packlist
33
+ if grep "^$oid" packlist
34
then
35
found_duplicate_object=true
36
echo "DUPLICATE OBJECT FOUND"
@@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
51
git rev-list --objects --all | grep -v file2 |
52
git pack-objects pack &&
53
# The second pack will contain the excluded object
54
- packsha1=$(git rev-list --objects --all | grep file2 |
54
+ packid=$(git rev-list --objects --all | grep file2 |
55
git pack-objects pack) &&
56
- >pack-$packsha1.keep &&
57
- objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
58
- sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
56
+ >pack-$packid.keep &&
57
+ oid=$(git verify-pack -v pack-$packid.idx | head -n 1 |
58
+ sed -e "s/^\($OID_REGEX\).*/\1/") &&
59
mv pack-* .git/objects/pack/ &&
60
git repack -A -d -l &&
61
git prune-packed &&
@@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
63
'
64
65
test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
66
- # build on $objsha1, $packsha1, and .keep state from previous
66
+ # build on $oid, $packid, and .keep state from previous
67
git repack -Adbl &&
68
test_has_duplicate_object true
69
'
70
71
test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
72
- # build on $objsha1, $packsha1, and .keep state from previous
72
+ # build on $oid, $packid, and .keep state from previous
73
git -c repack.writebitmaps=true repack -Adl &&
74
test_has_duplicate_object true
75
'
@@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
78
mkdir alt_objects &&
79
echo $(pwd)/alt_objects >.git/objects/info/alternates &&
80
echo content3 >file3 &&
81
- objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
81
+ oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
82
git add file3 &&
83
test_tick &&
84
git commit -m commit_file3 &&
@@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
124
test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
125
rm -f alt_objects/pack/*.keep &&
126
mv .git/objects/pack/* alt_objects/pack/ &&
127
- csha1=$(git rev-parse HEAD^{commit}) &&
127
+ coid=$(git rev-parse HEAD^{commit}) &&
128
git reset --hard HEAD^ &&
129
test_tick &&
130
git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
@@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
135
rm -f .git/objects/pack/* &&
136
mv pack-* .git/objects/pack/ &&
137
test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
138
- grep "^$csha1 " | sort | uniq | wc -l) &&
138
+ grep "^$coid " | sort | uniq | wc -l) &&
139
echo >.git/objects/info/alternates &&
140
- test_must_fail git show $csha1
140
+ test_must_fail git show $coid
141
'
142
143
test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
144
echo $(pwd)/alt_objects >.git/objects/info/alternates &&
145
- echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
145
+ echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
146
rm -f .git/objects/pack/* &&
147
mv pack-* .git/objects/pack/ &&
148
# The pack-objects call on the next line is equivalent to
@@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
152
rm -f .git/objects/pack/* &&
153
mv pack-* .git/objects/pack/ &&
154
test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
155
- grep "^$csha1 " | sort | uniq | wc -l) &&
155
+ grep "^$coid " | sort | uniq | wc -l) &&
156
echo >.git/objects/info/alternates &&
157
- test_must_fail git show $csha1
157
+ test_must_fail git show $coid
158
'
159
160
test_expect_success 'objects made unreachable by grafts only are kept' '