t5313: make test hash independent
Make this test hash independent by computing the length of the object offsets and looking up values which will hash to object IDs with the right properties. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 7, 2020 at 00:52 UTC
a30f93b14378c285d936255b9749a1491765b9f6
1 file changed
+15
-4
t/t5313-pack-bounds-checks.sh
+15
-4
@@ -38,16 +38,27 @@ munge () {
38
# for the initial, and another ofs(4*nr) past that for the extended.
39
#
40
ofs_table () {
41
- echo $((4 + 4 + 4*256 + 20*$1 + 4*$1))
41
+ echo $((4 + 4 + 4*256 + $(test_oid rawsz)*$1 + 4*$1))
42
}
43
extended_table () {
44
echo $(($(ofs_table "$1") + 4*$1))
45
}
46
47
+test_expect_success 'setup' '
48
+ test_oid_init &&
49
+ test_oid_cache <<-EOF
50
+ oid000 sha1:1485
51
+ oid000 sha256:4222
52
+
53
+ oidfff sha1:74
54
+ oidfff sha256:1350
55
+ EOF
56
+'
57
+
58
test_expect_success 'set up base packfile and variables' '
59
# the hash of this content starts with ff, which
60
# makes some later computations much simpler
50
- echo 74 >file &&
61
+ echo $(test_oid oidfff) >file &&
62
git add file &&
63
git commit -m base &&
64
git repack -ad &&
@@ -140,10 +151,10 @@ test_expect_success 'bogus offset inside v2 extended table' '
151
# an extended table (if the first object were larger than 2^31).
152
#
153
# Note that the value is important here. We want $object as
143
- # the second entry in sorted-sha1 order. The sha1 of 1485 starts
154
+ # the second entry in sorted-hash order. The hash of this object starts
155
# with "000", which sorts before that of $object (which starts
156
# with "fff").
146
- second=$(echo 1485 | git hash-object -w --stdin) &&
157
+ second=$(test_oid oid000 | git hash-object -w --stdin) &&
158
do_pack "$object $second" --index-version=2 &&
159
160
# We have to make extra room for the table, so we cannot