Volume XXII, number 279Tuesday, October 6, 2026Latest message 46 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patchmidx-write: skip empty incremental layers

5 messages between Sep 8, 2026 and Sep 15, 2026, from Pia Park, Taylor Blau.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Pia ParkSep 8, 2026, 01:46 UTC on lore

An incremental MIDX write can find new packs without finding any new objects, either because the packs are empty or because their objects are already indexed by an earlier layer.

The existing early exit checks the number of packs, so these cases publish a zero-object layer without a reverse index. A subsequent incremental write with --bitmap fails when loading that reverse index.

Reproducible on master as of b8242b093d9e941a34460d715e3ce616a34ac3fe (2026-09-07), using:

    git init --bare --object-format=sha1 empty.git &&
    (
        cd empty.git &&
        git config midx.version 2 &&
        git pack-objects objects/pack/pack </dev/null &&
        git multi-pack-index write --incremental --bitmap &&
        git multi-pack-index write --incremental --bitmap
    )

The first write succeeds but publishes the empty layer 3c8853aad425100c5ee2ee22209bb0bb3df9ca37. The second exits with status 255, reporting "could not load reverse index for MIDX".

Return success through the existing cleanup path when
compute_sorted_entries() finds no entries for a non-compacting
incremental write. This prevents publishing an empty layer that causes
subsequent incremental writes with --bitmap to fail with exit status
255. Exit before acquiring a lock or creating a temporary MIDX file,
leaving the existing chain untouched.

Add regression tests for empty initial layers, empty packs, and packs containing only duplicate objects. Check silent success, preservation of the existing chain and file list, and subsequent writes that add new objects.

Signed-off-by: Pia Park <pia@pierre.co>
---
Built with DEVELOPER=1 and ran these scripts before and after:
  t5319-multi-pack-index.sh
  t5326-multi-pack-bitmaps.sh
  t5327-multi-pack-bitmaps-rev.sh
  t5332-multi-pack-reuse.sh
  t5334-incremental-multi-pack-index.sh
  t5335-compact-multi-pack-index.sh
  t7700-repack.sh
  t7705-repack-incremental-midx.sh

All 881 baseline tests and all 884 tests with the patch passed. The three new regressions fail on the unpatched build. Test lint and whitespace checks passed.

Both empty and duplicate-only pack reproductions also fail on a fresh, unmodified build of upstream master at the base commit shown below.

 midx-write.c                            |  5 +++
 t/t5334-incremental-multi-pack-index.sh | 58 +++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
Show changes to 2 files +63 −0

midx-write.c, t/t5334-incremental-multi-pack-index.sh

diff --git a/midx-write.c b/midx-write.c
index 8537102254..cdb2ef0474 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1518,6 +1518,11 @@ static int write_midx_internal(struct write_midx_opts *opts)
 
 	compute_sorted_entries(&ctx, start_pack);
 
+	if (ctx.incremental && !ctx.compact && !ctx.entries_nr) {
+		result = 0;
+		goto cleanup;
+	}
+
 	ctx.large_offsets_needed = 0;
 	for (size_t i = 0; i < ctx.entries_nr; i++) {
 		if (ctx.entries[i].offset > 0x7fffffff)
diff --git a/t/t5334-incremental-multi-pack-index.sh b/t/t5334-incremental-multi-pack-index.sh
index f0b82b5f65..4bdfa61d38 100755
--- a/t/t5334-incremental-multi-pack-index.sh
+++ b/t/t5334-incremental-multi-pack-index.sh
@@ -195,4 +195,62 @@ 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>err &&
+			test_must_be_empty out &&
+			test_must_be_empty err &&
+			test_dir_is_empty "$midxdir" || return 1
+		done &&
+
+		write_midx_layer &&
+		test_line_count = 1 "$midx_chain" &&
+		git multi-pack-index verify
+	)
+'
+
+for pack in empty duplicate
+do
+	test_expect_success "skip MIDX layer with $pack pack" '
+		git init "$pack-pack" &&
+		(
+			cd "$pack-pack" &&
+			git config maintenance.auto false &&
+			write_midx_layer &&
+
+			if test "$pack" = duplicate
+			then
+				git rev-parse HEAD^{tree} >in
+			else
+				>in
+			fi &&
+			git pack-objects $packdir/pack <in &&
+			cp "$midx_chain" chain.expect &&
+			ls "$packdir" "$midxdir" >files.expect &&
+
+			for bitmap in --bitmap --no-bitmap
+			do
+				git multi-pack-index write --incremental "$bitmap" >out 2>err &&
+				test_must_be_empty out &&
+				test_must_be_empty err &&
+				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
+		)
+	'
+done
+
 test_done

base-commit: b8242b093d9e941a34460d715e3ce616a34ac3fe
-- 
2.55.0
Taylor BlauSep 8, 2026, 04:09 UTC in reply to Pia Park on lore

Re: [PATCH] midx-write: skip empty incremental layers

On Mon, Sep 07, 2026 at 06:46:40PM -0700, Pia Park wrote:
Show 5 quoted lines
> An incremental MIDX write can find new packs without finding any new
> objects, either because the packs are empty or because their objects
> are already indexed by an earlier layer.
>
> The existing early exit checks the number of packs, so these cases
First, thanks for working on this :-).

Second, what you wrote makes sense. It may be worth saying "[...] checks *only* the number of packs", or "[...] but not the number of objects".

Show 5 quoted lines
> publish a zero-object layer without a reverse index. A subsequent
> incremental write with --bitmap fails when loading that reverse index.
>
> Reproducible on master as of
> b8242b093d9e941a34460d715e3ce616a34ac3fe (2026-09-07), using:
Nit: we typically would abbreviate this using the "reference" pretty
formatter, as in:
    b8242b093d (The 23rd batch, 2026-09-07)

, but I think that it would be more interesting to include the commit that introduced this breakage, which I would guess (though haven't bisected) that we've had this bug at least as long as we've been able to write incremental MIDXs. Though see below for perhaps an earlier origin.

Show 13 quoted lines
>
>     git init --bare --object-format=sha1 empty.git &&
>     (
>         cd empty.git &&
>         git config midx.version 2 &&
>         git pack-objects objects/pack/pack </dev/null &&
>         git multi-pack-index write --incremental --bitmap &&
>         git multi-pack-index write --incremental --bitmap
>     )
>
> The first write succeeds but publishes the empty layer
> 3c8853aad425100c5ee2ee22209bb0bb3df9ca37. The second exits with status
> 255, reporting "could not load reverse index for MIDX".

Right. This patch message suggests (and I agree with) the fact that the first layer wrote anything at all is a bug.

It only happened to work because the first invocation did not require loading the empty reverse index, and so did not read the corruption that it just wrote. The second invocation notices the bug because we eagerly read reverse indexes for pack(s) in previous layer(s) when writing reachability bitmaps.

That makes me wonder whether this bug is unique to incremental MIDXs at all. I tried testing this out locally with:

    git.compile init --bare empty.git &&
    (
      cd empty.git &&
      git.compile pack-objects objects/pack/pack </dev/null &&
      git.compile multi-pack-index write
    )
, and it happily wrote a MIDX.
Show 6 quoted lines
> Return success through the existing cleanup path when
> compute_sorted_entries() finds no entries for a non-compacting
> incremental write. This prevents publishing an empty layer that causes
> subsequent incremental writes with --bitmap to fail with exit status
> 255. Exit before acquiring a lock or creating a temporary MIDX file,
> leaving the existing chain untouched.

So I wonder if we should apply the fix even earlier in write_midx_internal(), perhaps like:

--- 8< --- git rev-parse 2>/dev/null || cd ~/src/git; git: line 0: cd: /Users/ttaylorr/src/git: No such file or directory

Show changes to midx-write.c +2 −3
diff --git a/midx-write.c b/midx-write.c
index 580724d21a..5b2aa9acc8 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);
+		error(_("no objects to index."));
+		goto cleanup;
 	}

 	if (ctx.incremental) {
--- >8 ---

(as an aside, we can probably rework those error messages to be a bit
more descriptive, perhaps, "cannot create a multi-pack-index without any
packs". But that is besides the point of your patch.)

> diff --git a/midx-write.c b/midx-write.c
> index 8537102254..cdb2ef0474 100644
> --- a/midx-write.c
> +++ b/midx-write.c
> @@ -1518,6 +1518,11 @@ static int write_midx_internal(struct write_midx_opts *opts)
>
>  	compute_sorted_entries(&ctx, start_pack);
>
> +	if (ctx.incremental && !ctx.compact && !ctx.entries_nr) {
> +		result = 0;
> +		goto cleanup;
> +	}
> +

Hmm. So we will avoid writing an empty MIDX when we have no object
entries, but only when doing a non-compact, incremental write? I imagine
that we would want similar treatment for both incremental and
non-incremental MIDXs, regardless of whether we are compacting.

> diff --git a/t/t5334-incremental-multi-pack-index.sh b/t/t5334-incremental-multi-pack-index.sh
> index f0b82b5f65..4bdfa61d38 100755
> --- a/t/t5334-incremental-multi-pack-index.sh
> +++ b/t/t5334-incremental-multi-pack-index.sh

I suspect that these tests will change a bit, so I'll avoid reviewing
them too carefully for the time being. I am glad, however, that you are
testing cases besides explicitly empty packs, e.g., dropping objects
which are represented in earlier layers.

Thanks,
Taylor
Pia ParkSep 8, 2026, 07:10 UTC in reply to Taylor Blau on lore

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

A MIDX write can find packs without finding any objects, either because the packs are empty or because an incremental write finds only objects already indexed by an earlier layer. The existing early exit checks only the number of packs, so these cases publish a zero-object MIDX without a reverse index.

Empty MIDXs were already published by 662148c435 (midx: write object offsets, 2018-07-12); the failure mode appeared in 27afc272c4 (midx: implement writing incremental MIDX bitmaps, 2025-03-20), when incremental bitmap writes began loading reverse indexes from prior layers.

Reproducible on master as of b8242b093d (The 23rd batch, 2026-09-07), starting with a non-incremental write:

    git init --bare --object-format=sha1 empty.git &&
    (
        cd empty.git &&
        git pack-objects objects/pack/pack </dev/null &&
        git multi-pack-index write &&
        git multi-pack-index write --incremental --bitmap
    )

The first write succeeds but publishes an empty MIDX, which also fails verification with "the midx contains no oid". The second write exits with status 255, reporting "could not load reverse index for MIDX". Starting with an incremental write has the same problem.

Exit before publication whenever the computed entry list is empty, for both non-incremental and incremental writes, including compaction. Take the existing cleanup path after pack/drop validation and before acquiring a lock or creating a temporary MIDX file. This leaves existing MIDX files untouched and preserves the error when there are no pack files to index.

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.

Test empty packs in a bare repository, empty incremental layers, and packs containing only objects indexed by an earlier layer. Check silent success, preservation of existing files, and subsequent writes that add new objects. Update the existing bitmap test to expect neither an empty MIDX nor a bitmap.

Signed-off-by: Pia Park <pia@pierre.co>
---
Thanks, Taylor. I kept exit status 0 because empty-object writes
already succeed, including when --bitmap emits its warning. Would you
prefer an error here instead? The existing no-pack-files error is
unchanged.
Changes since v1:
* Apply the check to all write modes, including compaction, at the
  location in your sketch, after pack/drop validation.
* Preserve exit status 0 and skip empty publication silently.
* Add the non-incremental bare-repository reproduction and check later
  incremental and non-incremental bitmap writes with real objects.
* Update t5326's existing test that expected an empty MIDX and a warning.
  Keep explicit empty-pack and duplicate-only incremental tests.
* Identify the verified 2018 empty-MIDX behavior and the 2025 introduction
  of the reverse-index failure, using reference-format citations.

The implementation passed 885 tests across the eight MIDX/bitmap/repack scripts. After the test-only revisions, all 481 tests in the three changed scripts passed, along with test lint and whitespace checks.

 midx-write.c                            |  5 +-
 t/t5319-multi-pack-index.sh             | 35 ++++++++++++
 t/t5326-multi-pack-bitmaps.sh           | 13 +++--
 t/t5334-incremental-multi-pack-index.sh | 75 +++++++++++++++++++++++++
 4 files changed, 119 insertions(+), 9 deletions(-)
Show changes to 4 files +119 −9

midx-write.c, t/t5319-multi-pack-index.sh, t/t5326-multi-pack-bitmaps.sh, t/t5334-incremental-multi-pack-index.sh

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;
 	}
 
 	if (ctx.incremental) {
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 &&
+
+		for bitmap in "" --bitmap
+		do
+			git multi-pack-index write $bitmap >out 2>&1 &&
+			test_must_be_empty out &&
+			test_path_is_missing objects/pack/multi-pack-index &&
+			ls objects/pack >files.actual &&
+			test_cmp files.expect files.actual || return 1
+		done &&
+
+		git multi-pack-index write --incremental --bitmap &&
+		test_dir_is_empty objects/pack/multi-pack-index.d &&
+
+		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
+	)
+'
+
 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 &&
 			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 &&
+			test_dir_is_empty "$midxdir" || return 1
+		done &&
+
+		write_midx_layer &&
+		test_line_count = 1 "$midx_chain" &&
+		git multi-pack-index verify
+	)
+'
+
+test_expect_success 'skip MIDX layer with empty pack' '
+	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 &&
+
+		for bitmap in --bitmap --no-bitmap
+		do
+			git multi-pack-index write --incremental "$bitmap" >out 2>&1 &&
+			test_must_be_empty out &&
+			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
+	)
+'
+
+test_expect_success 'skip MIDX layer with duplicate pack' '
+	git init duplicate-pack &&
+	(
+		cd duplicate-pack &&
+		git config maintenance.auto false &&
+		write_midx_layer &&
+
+		git rev-parse HEAD^{tree} >in &&
+		git pack-objects $packdir/pack <in &&
+		cp "$midx_chain" chain.expect &&
+		ls "$packdir" "$midxdir" >files.expect &&
+
+		for bitmap in --bitmap --no-bitmap
+		do
+			git multi-pack-index write --incremental "$bitmap" >out 2>&1 &&
+			test_must_be_empty out &&
+			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
+	)
+'
+
 test_done
Taylor BlauSep 8, 2026, 15:06 UTC in reply to Pia Park on lore

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

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.

Show 13 quoted lines
> 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.

Show 14 quoted lines
> 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.

Show 5 quoted lines
> +
> +		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.

Show 13 quoted lines
> +		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.

Show 24 quoted lines
> +	)
> +'
> +
>  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.

Show 34 quoted lines
>  			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?

Show 6 quoted lines
> +			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.
> +	)
> +'
> +
> +test_expect_success 'skip MIDX layer with empty pack' '
Perhaps s/skip/& intermediate/ to distinguish from the previous test?
Show 9 quoted lines
> +	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.

Show 5 quoted lines
> +
> +		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.
Show 9 quoted lines
> +			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.
> +	)
> +'
> +
> +test_expect_success 'skip MIDX layer with duplicate pack' '
Same comments as above, though otherwise this test looks good.

Thanks, Taylor

Pia ParkSep 15, 2026, 14:25 UTC on lore

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

Hi! Just following up on Stolee’s suggestion to return silent success in the no-pack case. I’m happy to prepare v3 if there’s agreement on that approach.

I’ll also be at Git Merge in Lisbon this week and would be happy to chat in person if there’s a chance :)

On Tue, Sep 15, 2026 at 12:40 PM Pia Park <pia@pierre.co> wrote:
Show 227 quoted lines
>
> Hi! I’d like to ping on Stolee’s thoughts on returning silent success on the no-pack case. Happy to prepare v3 if there’s agreement on here.
>
> Plus, I’ll be in Git Merge Lisbon this week and would be happy to chat in person if theres chance :)
>
> On Tue, Sep 8, 2026 at 4:06 PM Taylor Blau <ttaylorr@openai.com> wrote:
>>
>> 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.
>>
>> > 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.
>>
>> > 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.
>>
>> > +
>> > +             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.
>>
>> > +             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.
>>
>> > +     )
>> > +'
>> > +
>> >  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.
>>
>> >                       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?
>>
>> > +                     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.
>>
>> > +     )
>> > +'
>> > +
>> > +test_expect_success 'skip MIDX layer with empty pack' '
>>
>> Perhaps s/skip/& intermediate/ to distinguish from the previous test?
>>
>> > +     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.
>>
>> > +
>> > +             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.
>>
>> > +                     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.
>>
>> > +     )
>> > +'
>> > +
>> > +test_expect_success 'skip MIDX layer with duplicate pack' '
>>
>> Same comments as above, though otherwise this test looks good.
>>
>> Thanks,
>> Taylor

Back to recent threads