bundle: add new version for use with SHA-256

Currently we detect the hash algorithm in use by the length of the
object ID.  This is inelegant and prevents us from using a different
hash algorithm that is also 256 bits in length.

Since we cannot extend the v2 format in a backward-compatible way, let's
add a v3 format, which is identical, except for the addition of
capabilities, which are prefixed by an at sign.  We add "object-format"
as the only capability and reject unknown capabilities, since we do not
have a network connection and therefore cannot negotiate with the other
side.

For compatibility, default to the v2 format for SHA-1 and require v3
for SHA-256.

In t5510, always use format v3 so we can be sure we produce consistent
results across hash algorithms.  Since head -n N lists the top N lines
instead of the Nth line, let's run our output through sed to normalize
it and compare it against a fixed value, which will make sure we get
exactly what we're expecting.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson
2020-07-29 23:14:20 +00:00
committed by Junio C Hamano
parent e74b606d47
commit c5aecfc866
7 changed files with 147 additions and 31 deletions

View File

@ -281,15 +281,19 @@ test_expect_success 'create bundle 1' '
cd "$D" &&
echo >file updated again by origin &&
git commit -a -m "tip" &&
git bundle create bundle1 master^..master
git bundle create --version=3 bundle1 master^..master
'
test_expect_success 'header of bundle looks right' '
head -n 4 "$D"/bundle1 &&
head -n 1 "$D"/bundle1 | grep "^#" &&
head -n 2 "$D"/bundle1 | grep "^-$OID_REGEX " &&
head -n 3 "$D"/bundle1 | grep "^$OID_REGEX " &&
head -n 4 "$D"/bundle1 | grep "^$"
cat >expect <<-EOF &&
# v3 git bundle
@object-format=$(test_oid algo)
-OID updated by origin
OID refs/heads/master
EOF
sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
test_cmp expect actual
'
test_expect_success 'create bundle 2' '