#!/bin/sh test_description='pack-objects multi-pack reuse' TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-bitmap.sh GIT_TEST_MULTI_PACK_INDEX=0 GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0 objdir=.git/objects packdir=$objdir/pack test_pack_reused () { test_trace2_data pack-objects pack-reused "$1" } test_packs_reused () { test_trace2_data pack-objects packs-reused "$1" } # pack_position objects && grep "$1" objects | cut -d" " -f1 } # test_pack_objects_reused_all test_pack_objects_reused_all () { : >trace2.txt && GIT_TRACE2_EVENT="$PWD/trace2.txt" \ git pack-objects --stdout --revs --all --delta-base-offset \ >got.pack && test_pack_reused "$1" test_pack_objects_reused () { : >trace2.txt && GIT_TRACE2_EVENT="$PWD/trace2.txt" \ git pack-objects --stdout --revs >got.pack && test_pack_reused "$1" in <<-EOF && $(git rev-parse C) ^$(git rev-parse A) EOF test_pack_objects_reused 6 2 in <<-EOF && $(git rev-parse E) ^$(git rev-parse D) EOF test_pack_objects_reused 3 1 in <<-EOF && $(git rev-parse E) ^$(git rev-parse D) EOF test_pack_objects_reused 3 1 f && git add f && test_tick && git commit -m "delta" && delta="$(git rev-parse HEAD)" && test_seq 64 >f && test_tick && git commit -a -m "base" && base="$(git rev-parse HEAD)" && test_commit other && git repack -d && have_delta "$(git rev-parse $delta:f)" "$(git rev-parse $base:f)" && git multi-pack-index write --bitmap && cat >in <<-EOF && $(git rev-parse other) ^$base EOF # We can only reuse the 3 objects corresponding to "other" from # the latest pack. # # This is because even though we want "delta", we do not want # "base", meaning that we have to inflate the delta/base-pair # corresponding to the blob in commit "delta", which bypasses # the pack-reuse mechanism. # # The remaining objects from the other pack are similarly not # reused because their objects are on the uninteresting side of # the query. test_pack_objects_reused 3 1 in <<-EOF && $(git rev-parse $base) ^$(git rev-parse $delta) EOF P="$(git pack-objects --revs $packdir/pack p1.objects <<-EOF && $(git rev-parse $base) ^$(git rev-parse $delta^) EOF cat >p2.objects <<-EOF && $(git rev-parse F) EOF p1="$(git pack-objects --revs $packdir/pack in <<-EOF && pack-$p1.idx pack-$p2.idx EOF git multi-pack-index write --bitmap --stdin-packs \ --preferred-pack=pack-$p1.pack expect && test_pack_objects_reused_all $(wc -l in && p="$(git pack-objects $packdir/pack