Skip to content

Commit

Permalink
amend! WIP: add a test for push --path-walk not reusing deltas
Browse files Browse the repository at this point in the history
TO-SQUASH: add a test for `push --path-walk` not reusing deltas

This constructs a test that demonstrates that `git -c
pack.usePathWalk=true push` avoids reusing deltas.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Dec 10, 2024
1 parent 0d196b3 commit 23b57a8
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions t/t5590-push-path-walk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ TEST_PASSES_SANITIZE_LEAK=true

test_expect_success 'setup bare repository and clone' '
git init --bare -b main bare.git &&
git --git-dir=bare.git config receive.unpackLimit 0 &&
git --git-dir bare.git commit-tree -m initial $EMPTY_TREE >head_oid &&
git --git-dir bare.git update-ref refs/heads/main $(cat head_oid) &&
git clone --bare bare.git clone.git
'
test_expect_success 'avoid reusing deltified objects' '
# construct two commits, one containing a file with the hex digits
# repeated 16 times, the next reducing that to 8 times. The crucial
# part is that the blob of the second commit is deltified _really_
# badly and it is therefore easy to detect if a `git push` reused that
# delta.
x="0123456789abcdef" &&
printf "$x$x$x$x$x$x$x$x" >x128 &&
printf "$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x$x" >x256 &&
oid128=$(git hash-object x128) &&
oid256=$(git hash-object x256) &&
pack=clone.git/objects/pack/pack-tmp.pack &&
pack_header 2 >$pack &&
Expand Down Expand Up @@ -46,14 +50,51 @@ test_expect_success 'avoid reusing deltified objects' '
printf "\x80\x02" >>$pack &&
# object size = 0x80 (encoded as 0x80 | (0x80 & 0x7f), 0x80 >> 7
printf "\x80\x01" >>$pack &&
# enourmously badly-deltified object: copy every single byte individually
# massively badly-deltified object: copy every single byte individually
# 0x80 = copy, 0x01 = use 1 byte to encode the offset (0), 0x10 = use 1 byte to encode the size (1, i.e. 0x01)
printf "$(printf "\\\\x91\\\\x%02x\\\\x01" $(test_seq 0 127))" >>$pack &&
# Manually-computed Adler32 checksum: 0x99c369c4
printf "\x99\xc3\x69\xc4" >>$pack &&
pack_trailer $pack &&
git index-pack -v $pack
git index-pack -v $pack &&
oid256=$(git hash-object x256) &&
printf "100755 blob $oid256\thex\n" >tree &&
tree_oid="$(git --git-dir=clone.git mktree <tree)" &&
commit_oid=$(git --git-dir=clone.git commit-tree \
-p $(git --git-dir=clone.git rev-parse main) \
-m 256 $tree_oid) &&
oid128=$(git hash-object x128) &&
printf "100755 blob $oid128\thex\n" >tree &&
tree_oid="$(git --git-dir=clone.git mktree <tree)" &&
commit_oid=$(git --git-dir=clone.git commit-tree \
-p $commit_oid \
-m 128 $tree_oid) &&
# Verify that the on-disk size of the delta object is suboptimal in the
# clone (see below why 18 bytes or smaller is the optimal size):
git index-pack --verify-stat clone.git/objects/pack/pack-*.pack >verify &&
size="$(sed -n "s/^$oid128 blob *\([^ ]*\).*/\1/p" <verify)" &&
test $size -gt 18 &&
git --git-dir=clone.git update-ref refs/heads/main $commit_oid &&
git --git-dir=clone.git -c pack.usePathWalk=true push origin main &&
git index-pack --verify-stat bare.git/objects/pack/pack-*.pack >verify &&
size="$(sed -n "s/^$oid128 blob *\([^ ]*\).*/\1/p" <verify)" &&
# The on-disk size of the delta object should be smaller than, or equal
# to, 18 bytes, as that would be the size if storing the payload
# uncompressed:
# 3 bytes: \x78\x01\x01
# + 2 bytes: zlib stream size
# + 2 bytes: but-wise complement of the zlib stream size
# + 7 bytes: payload
# (= 2 bytes for the size of tbe base object
# + 2 bytes for the size of the delta command
# + 3 bytes for the copy command)
# + 2 + 2 bytes: Adler32 checksum
test $size -le 18
'

test_done

0 comments on commit 23b57a8

Please sign in to comment.