t5320-delta-islands.sh [plain text]
#!/bin/sh
test_description='exercise delta islands'
. ./test-lib.sh
is_delta_base () {
delta_base=$(echo "$1" | git cat-file --batch-check='%(deltabase)') &&
echo >&2 "$1 has base $delta_base" &&
test "$delta_base" = "$2"
}
commit() {
blob=$({ test-tool genrandom "$2" 10240 && echo "$3"; } |
git hash-object -w --stdin) &&
tree=$(printf '100644 blob %s\tfile\n' "$blob" | git mktree) &&
commit=$(echo "$2-$3" | git commit-tree "$tree" ${4:+-p "$4"}) &&
git update-ref "refs/heads/$1" "$commit" &&
eval "$1"'=$(git rev-parse $1:file)' &&
eval "echo >&2 $1=\$$1"
}
test_expect_success 'setup commits' '
commit one seed 1 &&
commit two seed 12
'
test_expect_success 'vanilla repack deltas one against two' '
git repack -adf &&
is_delta_base $one $two
'
test_expect_success 'island repack with no island definition is vanilla' '
git repack -adfi &&
is_delta_base $one $two
'
test_expect_success 'island repack with no matches is vanilla' '
git -c "pack.island=refs/foo" repack -adfi &&
is_delta_base $one $two
'
test_expect_success 'separate islands disallows delta' '
git -c "pack.island=refs/heads/(.*)" repack -adfi &&
! is_delta_base $one $two &&
! is_delta_base $two $one
'
test_expect_success 'same island allows delta' '
git -c "pack.island=refs/heads" repack -adfi &&
is_delta_base $one $two
'
test_expect_success 'coalesce same-named islands' '
git \
-c "pack.island=refs/(.*)/one" \
-c "pack.island=refs/(.*)/two" \
repack -adfi &&
is_delta_base $one $two
'
test_expect_success 'island restrictions drop reused deltas' '
git repack -adfi &&
is_delta_base $one $two &&
git -c "pack.island=refs/heads/(.*)" repack -adi &&
! is_delta_base $one $two &&
! is_delta_base $two $one
'
test_expect_success 'island regexes are left-anchored' '
git -c "pack.island=heads/(.*)" repack -adfi &&
is_delta_base $one $two
'
test_expect_success 'island regexes follow last-one-wins scheme' '
git \
-c "pack.island=refs/heads/(.*)" \
-c "pack.island=refs/heads/" \
repack -adfi &&
is_delta_base $one $two
'
test_expect_success 'setup shared history' '
commit root shared root &&
commit one shared 1 root &&
commit two shared 12-long root
'
test_expect_success 'vanilla delta goes between branches' '
git repack -adf &&
is_delta_base $one $two &&
is_delta_base $root $two
'
test_expect_success 'deltas allowed against superset islands' '
git -c "pack.island=refs/heads/(.*)" repack -adfi &&
is_delta_base $one $root &&
is_delta_base $two $root
'
test_expect_success 'island core places core objects first' '
cat >expect <<-EOF &&
$root
$two
EOF
git -c "pack.island=refs/heads/(.*)" \
-c "pack.islandcore=one" \
repack -adfi &&
git verify-pack -v .git/objects/pack/*.pack |
cut -d" " -f1 |
egrep "$root|$two" >actual &&
test_cmp expect actual
'
test_expect_success 'unmatched island core is not fatal' '
git -c "pack.islandcore=one" repack -adfi
'
test_done