Thread (4 messages) 4 messages, 2 authors, 24d ago

Re: [PATCH v2] midx-write: skip writes with no object entries

From: Taylor Blau <hidden>
Date: 2026-09-08 15:06:48

On Tue, Sep 08, 2026 at 12:10:16AM -0700, Pia Park wrote:
Return success silently. Empty-object writes already return 0, including
when --bitmap warns, so preserve that exit status for existing callers
while omitting the warning and empty MIDX.
I think that this is OK, and it matches the behavior of other builtins,
e.g., running "git repack -d" twice in a row such that the second
invocation has no objects to pack. However, I think that if we want to
make this case return successfully when no objects are present, we
should apply the same treatment to the case where no packs are present.

But I want to make sure that others are on the same page. I would be
curious to hear Stolee's (CC'd) opinion on whether returning silent
success in both cases makes sense.
quoted hunk ↗ jump to hunk
diff --git a/midx-write.c b/midx-write.c
index 8537102254..3038bbfad2 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1617,9 +1617,8 @@ static int write_midx_internal(struct write_midx_opts *opts)
 	}

 	if (!ctx.entries_nr) {
-		if (opts->flags & MIDX_WRITE_BITMAP)
-			warning(_("refusing to write multi-pack .bitmap without any objects"));
-		opts->flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP);
+		result = 0;
+		goto cleanup;
Looks good, though let's make sure others agree that this is the right
approach. If they do, I'd recommend changing the no packs case to also
return zero either in a small preparatory patch.
quoted hunk ↗ jump to hunk
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 68143cb5b7..c239a87d10 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -54,6 +54,41 @@ test_expect_success "don't write midx with no packs" '
 	test_path_is_missing pack/multi-pack-index
 '

+test_expect_success 'skip non-incremental MIDX with no objects' '
+	git init --bare empty.git &&
+	(
+		cd empty.git &&
+		git pack-objects objects/pack/pack </dev/null &&
+		ls objects/pack >files.expect &&
I think it's fine to drop files.expect and files.actual here. Testing
that the MIDX write does nothing should be sufficient here.
quoted hunk ↗ jump to hunk
+
+		for bitmap in "" --bitmap
+		do
+			git multi-pack-index write $bitmap >out 2>&1 &&
+			test_must_be_empty out &&
I think it's fine to write "git multi-pack-index write $bitmap" without
the redirection, so that this is:

    for opt in "" --bitmap
    do
        git multi-pack-index write $opt &&
        test_path_is_missing $objdir/pack/multi-pack-index || return 1
    done &&

+		git multi-pack-index write --incremental --bitmap &&
+		test_dir_is_empty objects/pack/multi-pack-index.d &&
I was going to ask whether we wanted to test this case with and without
the "--bitmap" option as well, and likewise recommend that tthis test go
in t5334 instead. But such a pair of tests already exists in t5334, so I
think we can safely drop this hunk.
quoted hunk ↗ jump to hunk
+		echo blob | git hash-object -w --stdin >in &&
+		git pack-objects objects/pack/pack <in &&
+		git multi-pack-index write --incremental --bitmap &&
+		test_line_count = 1 objects/pack/multi-pack-index.d/multi-pack-index-chain &&
+		git multi-pack-index verify &&
+
+		echo another | git hash-object -w --stdin >in &&
+		git pack-objects objects/pack/pack <in &&
+		git multi-pack-index write --bitmap &&
+		test_path_is_file objects/pack/multi-pack-index &&
+		midx="$(midx_checksum objects)" &&
+		test_path_is_file objects/pack/multi-pack-index-$midx.bitmap &&
+		git multi-pack-index verify
These two blocks are testing normal MIDX operations that are well
covered elsewhere in the test suite. I think we can drop these safely.
quoted hunk ↗ jump to hunk
+	)
+'
+
 test_expect_success SHA1 'warn if a midx contains no oid' '
 	cp "$TEST_DIRECTORY"/t5319/no-objects.midx $objdir/pack/multi-pack-index &&
 	test_must_fail git multi-pack-index verify &&
diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh
index 86beab1dae..490008d1d7 100755
--- a/t/t5326-multi-pack-bitmaps.sh
+++ b/t/t5326-multi-pack-bitmaps.sh
@@ -305,7 +305,7 @@ test_midx_bitmap_cases () {
 		)
 	'

-	test_expect_success 'no .bitmap is written without any objects' '
+	test_expect_success 'no MIDX or .bitmap is written without any objects' '
 		rm -fr repo &&
 		git init repo &&
 		test_when_finished "rm -fr repo" &&
@@ -318,13 +318,14 @@ test_midx_bitmap_cases () {
 			pack-$empty.idx
 			EOF

+			ls $objdir/pack >files.expect &&
Similar comments here. It should be fine to drop the assertion on
files.expect, along with the content out stdout.
quoted hunk ↗ jump to hunk
 			git multi-pack-index write --bitmap --stdin-packs \
-				<packs 2>err &&
+				<packs >out 2>&1 &&

-			test_grep "bitmap without any objects" err &&
-
-			test_path_is_file $midx &&
-			test_path_is_missing $midx-$(midx_checksum $objdir).bitmap
+			test_must_be_empty out &&
+			test_path_is_missing $midx &&
+			ls $objdir/pack >files.actual &&
+			test_cmp files.expect files.actual
 		)
 	'
diff --git a/t/t5334-incremental-multi-pack-index.sh b/t/t5334-incremental-multi-pack-index.sh
index f0b82b5f65..fbcc19feeb 100755
--- a/t/t5334-incremental-multi-pack-index.sh
+++ b/t/t5334-incremental-multi-pack-index.sh
@@ -195,4 +195,79 @@ test_expect_success 'non-incremental write with existing incremental chain' '
 	)
 '

+test_expect_success 'skip initial MIDX layer with no objects' '
+	git init empty &&
+	(
+		cd empty &&
+		git config maintenance.auto false &&
+		git pack-objects $packdir/pack </dev/null &&
+
+		for bitmap in --bitmap --no-bitmap
+		do
+			git multi-pack-index write --incremental "$bitmap" >out 2>&1 &&
+			test_must_be_empty out &&
Same comment about asserting the contents of stdout here as well. I am a
little confused by this test, though, since there are no packs present
in "empty". Shouldn't we be hitting the "no pack files to index" error
here?
quoted hunk ↗ jump to hunk
+			test_dir_is_empty "$midxdir" || return 1
+		done &&
+
+		write_midx_layer &&
+		test_line_count = 1 "$midx_chain" &&
+		git multi-pack-index verify
We can drop this last block as well.
quoted hunk ↗ jump to hunk
+	)
+'
+
+test_expect_success 'skip MIDX layer with empty pack' '
Perhaps s/skip/& intermediate/ to distinguish from the previous test?
quoted hunk ↗ jump to hunk
+	git init empty-pack &&
+	(
+		cd empty-pack &&
+		git config maintenance.auto false &&
+		write_midx_layer &&
+
+		git pack-objects $packdir/pack </dev/null &&
+		cp "$midx_chain" chain.expect &&
+		ls "$packdir" "$midxdir" >files.expect &&
I think testing that the MIDX chain file is unmodified makes sense, but
no need to test the content of $packdir and $midxdir itself. If there is
a reason to test those as well, please ensure to sort them first before
comparison.
quoted hunk ↗ jump to hunk
+
+		for bitmap in --bitmap --no-bitmap
+		do
+			git multi-pack-index write --incremental "$bitmap" >out 2>&1 &&
+			test_must_be_empty out &&
Same comment as above.
quoted hunk ↗ jump to hunk
+			test_cmp chain.expect "$midx_chain" &&
+			ls "$packdir" "$midxdir" >files.actual &&
+			test_cmp files.expect files.actual || return 1
+		done &&
+
+		write_midx_layer &&
+		test_line_count = 2 "$midx_chain" &&
+		git multi-pack-index verify &&
+		git rev-list --test-bitmap 2.2
Likewise.
quoted hunk ↗ jump to hunk
+	)
+'
+
+test_expect_success 'skip MIDX layer with duplicate pack' '
Same comments as above, though otherwise this test looks good.

Thanks,
Taylor
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help