Thread (7 messages) read the whole thread 7 messages, 2 authors, 6d ago
COOLING6d

[PATCH 1/5] t5308: test reverse indexes with duplicate objects

From: Taylor Blau <hidden>
Date: 2026-07-24 21:05:58
Subsystem: the rest · Maintainer: Linus Torvalds

A non-strict .idx has one entry for each object in the pack, even when
multiple entries have the same object ID. Thus a pack ordered A, B, A,
C has two .idx entries for A at distinct offsets. The corresponding
per-pack reverse index must represent both entries and map them back to
physical pack order.

Existing reverse-index tests do not cover packs with duplicate objects.
Add one and check that %(objectsize:disk) for B stops at the second A,
rather than extending through it to C. Exercise both the on-disk and
in-memory reverse-index implementations.

As part of validating Git's handling of packs containing duplicate
objects, cover their per-pack reverse indexes.

Signed-off-by: Taylor Blau <redacted>
---
 t/t5308-pack-detect-duplicates.sh | 39 +++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff --git a/t/t5308-pack-detect-duplicates.sh b/t/t5308-pack-detect-duplicates.sh
index 0f84137867..4ff8f5b449 100755
--- a/t/t5308-pack-detect-duplicates.sh
+++ b/t/t5308-pack-detect-duplicates.sh
@@ -27,6 +27,11 @@ HI_SHA1=$EMPTY_BLOB
 # duplicate runs).
 MISSING_SHA1=$(test_oid missing_oid)
 
+# Three distinct objects for tests where physical pack order matters.
+A=$(test_oid packlib_7_0)
+B=$LO_SHA1
+C=$HI_SHA1
+
 # git will never intentionally create packfiles with
 # duplicate objects, so we have to construct them by hand.
 #
@@ -72,6 +77,40 @@ test_expect_success 'lookup in duplicated pack' '
 	test_cmp expect actual
 '
 
+test_expect_success 'duplicate entries remain in pack reverse index' '
+	clear_packs &&
+	{
+		pack_header 4 &&
+		pack_obj $A &&
+		pack_obj $B &&
+		pack_obj $A &&
+		pack_obj $C
+	} >physical-order.pack &&
+	pack_trailer physical-order.pack &&
+
+	test_must_fail git index-pack --rev-index --stdin --strict \
+		<physical-order.pack 2>err &&
+	test_grep "appears twice in the pack" err &&
+
+	git index-pack --rev-index --stdin <physical-order.pack &&
+	git show-index <"$(ls .git/objects/pack/pack-*.idx)" >offsets.raw &&
+
+	sort -n offsets.raw | grep -A1 "$B" | cut -d" " -f1 >adjacent &&
+	echo $(($(tail -n1 adjacent) - $(head -n1 adjacent))) >expect &&
+	echo "$B" >in &&
+
+	GIT_TEST_REV_INDEX_DIE_IN_MEMORY=1 \
+		git cat-file --batch-check="%(objectsize:disk)" \
+		<in >actual.disk &&
+	GIT_TEST_REV_INDEX_DIE_ON_DISK=1 \
+		git -c pack.readReverseIndex=false \
+		cat-file --batch-check="%(objectsize:disk)" \
+		<in >actual.mem  &&
+
+	test_cmp expect actual.disk &&
+	test_cmp expect actual.mem
+'
+
 test_expect_success 'index-pack can reject packs with duplicates' '
 	clear_packs &&
 	create_pack dups.pack 2 &&
-- 
2.55.0.383.gde07827a19
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help