summaryrefslogtreecommitdiff
path: root/t/t5319-multi-pack-index.sh
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2020-08-17 14:04:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-17 23:45:20 (GMT)
commitd96075428a9a1de720f6019242dadb5dbaa0ac16 (patch)
tree35957b261149e0a03dad0115bef0c1f2fd99fa75 /t/t5319-multi-pack-index.sh
parent665d70ad033b115d8c14cdc2bcecf6c8b1947260 (diff)
downloadgit-d96075428a9a1de720f6019242dadb5dbaa0ac16.zip
git-d96075428a9a1de720f6019242dadb5dbaa0ac16.tar.gz
git-d96075428a9a1de720f6019242dadb5dbaa0ac16.tar.bz2
multi-pack-index: use hash version byte
Similar to the commit-graph format, the multi-pack-index format has a byte in the header intended to track the hash version used to write the file. This allows one to interpret the hash length without having the context of the repository config specifying the hash length. This was not modified as part of the SHA-256 work because the hash length was automatically up-shifted due to that config. Since we have this byte available, we can make the file formats more obviously incompatible instead of relying on other context from the repository. Add a new oid_version() method in midx.c similar to the one in commit-graph.c. This is specifically made separate from that implementation to avoid artificially linking the formats. The test impact requires a few more things than the corresponding change in the commit-graph format. Specifically, 'test-tool read-midx' was not writing anything about this header value to output. Since the value available in 'struct multi_pack_index' is hash_len instead of a version value, we output "20" or "32" instead of "1" or "2". Since we want a user to not have their Git commands fail if their multi-pack-index has the incorrect hash version compared to the repository's hash version, we relax the die() to an error() in load_multi_pack_index(). This has some effect on 'git multi-pack-index verify' as we need to check that a failed parse of a file that exists is actually a verify error. For that test that checks the hash version matches, we change the corrupted byte from "2" to "3" to ensure the test fails for both hash algorithms. Helped-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t5319-multi-pack-index.sh')
-rwxr-xr-xt/t5319-multi-pack-index.sh43
1 files changed, 39 insertions, 4 deletions
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 7dfff0f..09cbca4 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -5,6 +5,8 @@ test_description='multi-pack-indexes'
objdir=.git/objects
+HASH_LEN=$(test_oid rawsz)
+
midx_read_expect () {
NUM_PACKS=$1
NUM_OBJECTS=$2
@@ -13,7 +15,7 @@ midx_read_expect () {
EXTRA_CHUNKS="$5"
{
cat <<-EOF &&
- header: 4d494458 1 $NUM_CHUNKS $NUM_PACKS
+ header: 4d494458 1 $HASH_LEN $NUM_CHUNKS $NUM_PACKS
chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS
num_objects: $NUM_OBJECTS
packs:
@@ -46,7 +48,7 @@ test_expect_success "don't write midx with no packs" '
test_path_is_missing pack/multi-pack-index
'
-test_expect_success "Warn if a midx contains no oid" '
+test_expect_success SHA1 'warn if a midx contains no oid' '
cp "$TEST_DIRECTORY"/t5319/no-objects.midx $objdir/pack/multi-pack-index &&
test_must_fail git multi-pack-index verify &&
rm $objdir/pack/multi-pack-index
@@ -198,6 +200,40 @@ test_expect_success 'write midx with twelve packs' '
compare_results_with_midx "twelve packs"
+test_expect_success 'warn on improper hash version' '
+ git init --object-format=sha1 sha1 &&
+ (
+ cd sha1 &&
+ git config core.multiPackIndex true &&
+ test_commit 1 &&
+ git repack -a &&
+ git multi-pack-index write &&
+ mv .git/objects/pack/multi-pack-index ../mpi-sha1
+ ) &&
+ git init --object-format=sha256 sha256 &&
+ (
+ cd sha256 &&
+ git config core.multiPackIndex true &&
+ test_commit 1 &&
+ git repack -a &&
+ git multi-pack-index write &&
+ mv .git/objects/pack/multi-pack-index ../mpi-sha256
+ ) &&
+ (
+ cd sha1 &&
+ mv ../mpi-sha256 .git/objects/pack/multi-pack-index &&
+ git log -1 2>err &&
+ test_i18ngrep "multi-pack-index hash version 2 does not match version 1" err
+ ) &&
+ (
+ cd sha256 &&
+ mv ../mpi-sha1 .git/objects/pack/multi-pack-index &&
+ git log -1 2>err &&
+ test_i18ngrep "multi-pack-index hash version 1 does not match version 2" err
+ )
+'
+
+
test_expect_success 'verify multi-pack-index success' '
git multi-pack-index verify --object-dir=$objdir
'
@@ -243,7 +279,6 @@ test_expect_success 'verify bad signature' '
"multi-pack-index signature"
'
-HASH_LEN=$(test_oid rawsz)
NUM_OBJECTS=74
MIDX_BYTE_VERSION=4
MIDX_BYTE_OID_VERSION=5
@@ -272,7 +307,7 @@ test_expect_success 'verify bad version' '
'
test_expect_success 'verify bad OID version' '
- corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\02" $objdir \
+ corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\03" $objdir \
"hash version"
'