]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5326: demonstrate bitmap corruption after permutation
authorTaylor Blau <me@ttaylorr.com>
Tue, 25 Jan 2022 22:41:01 +0000 (17:41 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 Jan 2022 20:07:52 +0000 (12:07 -0800)
This patch demonstrates a cause of bitmap corruption that can occur when
the contents of the multi-pack index does not change, but the underlying
object order does.

In this example, we have a MIDX containing two packs, each with a
distinct set of objects (pack A corresponds to the tree, blob, and
commit from the first patch, and pack B corresponds to the second
patch).

First, a MIDX is written where the 'A' pack is preferred. As expected,
the bitmaps generated there are in-tact. But then, we generate an
identical MIDX with a different object order: this time preferring pack
'B'.

Due to a bug which will be explained and fixed in the following commit,
the MIDX is updated, but the .rev file is not, causing the .bitmap file
to be read incorrectly. Specifically, the .bitmap file will contain
correct data, but the auxiliary object order in the .rev file is stale,
causing readers to get confused by reading the new bitmaps using the old
object order.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5326-multi-pack-bitmaps.sh

index e187f90f29e2b592b4074add76d76212b9d0d729..0ca2868b0b2f929692a32fe56d105a6cb9066c54 100755 (executable)
@@ -395,4 +395,35 @@ test_expect_success 'hash-cache values are propagated from pack bitmaps' '
        )
 '
 
+test_expect_failure 'changing the preferred pack does not corrupt bitmaps' '
+       rm -fr repo &&
+       git init repo &&
+       test_when_finished "rm -fr repo" &&
+       (
+               cd repo &&
+
+               test_commit A &&
+               test_commit B &&
+
+               git rev-list --objects --no-object-names HEAD^ >A.objects &&
+               git rev-list --objects --no-object-names HEAD^.. >B.objects &&
+
+               A=$(git pack-objects $objdir/pack/pack <A.objects) &&
+               B=$(git pack-objects $objdir/pack/pack <B.objects) &&
+
+               cat >indexes <<-EOF &&
+               pack-$A.idx
+               pack-$B.idx
+               EOF
+
+               git multi-pack-index write --bitmap --stdin-packs \
+                       --preferred-pack=pack-$A.pack <indexes &&
+               git rev-list --test-bitmap A &&
+
+               git multi-pack-index write --bitmap --stdin-packs \
+                       --preferred-pack=pack-$B.pack <indexes &&
+               git rev-list --test-bitmap A
+       )
+'
+
 test_done