Skip to content

Commit 3699d69

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dcf9a74 commit 3699d69

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

t/t7700-repack.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ test_description='git repack works correctly'
66

77
commit_and_pack () {
88
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
1111
}
1212

1313
test_no_missing_in_packs () {
1414
myidx=$(ls -1 .git/objects/pack/*.idx) &&
1515
test_path_is_file "$myidx" &&
1616
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 &&
1818
git verify-pack -v $myidx >dest.raw &&
1919
cut -d" " -f1 dest.raw | sort >dest &&
2020
comm -23 orig dest >missing &&
2121
test_must_be_empty missing
2222
}
2323

24-
# we expect $packsha1 and $objsha1 to be defined
24+
# we expect $packid and $oid to be defined
2525
test_has_duplicate_object () {
2626
want_duplicate_object="$1"
2727
found_duplicate_object=false
2828
for p in .git/objects/pack/*.idx
2929
do
3030
idx=$(basename $p)
31-
test "pack-$packsha1.idx" = "$idx" && continue
31+
test "pack-$packid.idx" = "$idx" && continue
3232
git verify-pack -v $p >packlist || return $?
33-
if grep "^$objsha1" packlist
33+
if grep "^$oid" packlist
3434
then
3535
found_duplicate_object=true
3636
echo "DUPLICATE OBJECT FOUND"
@@ -51,25 +51,25 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
5151
git rev-list --objects --all | grep -v file2 |
5252
git pack-objects pack &&
5353
# 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 |
5555
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/") &&
5959
mv pack-* .git/objects/pack/ &&
6060
git repack -A -d -l &&
6161
git prune-packed &&
6262
test_has_duplicate_object false
6363
'
6464

6565
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
6767
git repack -Adbl &&
6868
test_has_duplicate_object true
6969
'
7070

7171
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
7373
git -c repack.writebitmaps=true repack -Adl &&
7474
test_has_duplicate_object true
7575
'
@@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
7878
mkdir alt_objects &&
7979
echo $(pwd)/alt_objects >.git/objects/info/alternates &&
8080
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) &&
8282
git add file3 &&
8383
test_tick &&
8484
git commit -m commit_file3 &&
@@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
124124
test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
125125
rm -f alt_objects/pack/*.keep &&
126126
mv .git/objects/pack/* alt_objects/pack/ &&
127-
csha1=$(git rev-parse HEAD^{commit}) &&
127+
coid=$(git rev-parse HEAD^{commit}) &&
128128
git reset --hard HEAD^ &&
129129
test_tick &&
130130
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' '
135135
rm -f .git/objects/pack/* &&
136136
mv pack-* .git/objects/pack/ &&
137137
test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
138-
grep "^$csha1 " | sort | uniq | wc -l) &&
138+
grep "^$coid " | sort | uniq | wc -l) &&
139139
echo >.git/objects/info/alternates &&
140-
test_must_fail git show $csha1
140+
test_must_fail git show $coid
141141
'
142142

143143
test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
144144
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 &&
146146
rm -f .git/objects/pack/* &&
147147
mv pack-* .git/objects/pack/ &&
148148
# 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
152152
rm -f .git/objects/pack/* &&
153153
mv pack-* .git/objects/pack/ &&
154154
test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
155-
grep "^$csha1 " | sort | uniq | wc -l) &&
155+
grep "^$coid " | sort | uniq | wc -l) &&
156156
echo >.git/objects/info/alternates &&
157-
test_must_fail git show $csha1
157+
test_must_fail git show $coid
158158
'
159159

160160
test_expect_success 'objects made unreachable by grafts only are kept' '

0 commit comments

Comments
 (0)