From: Taylor Blau <ttaylorr@openai.com>
To: Pia Park <pia@pierre.co>
Cc: git@vger.kernel.org, Taylor Blau <me@ttaylorr.com>,
Derrick Stolee <stolee@gmail.com>
Subject: Re: [PATCH v2] midx-write: skip writes with no object entries
Date: Tue, 8 Sep 2026 10:06:36 -0500 [thread overview]
Message-ID: <aqAkfGZtLJ97nG1m@com-79390> (raw)
In-Reply-To: <eef33827000cf106544174ed000129c2989af1cd.1788851232.git.pia@pierre.co>
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
prev parent reply other threads:[~2026-09-08 15:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 1:46 [PATCH] midx-write: skip empty incremental layers Pia Park
2026-09-08 4:09 ` Taylor Blau
2026-09-08 7:10 ` [PATCH v2] midx-write: skip writes with no object entries Pia Park
2026-09-08 15:06 ` Taylor Blau [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aqAkfGZtLJ97nG1m@com-79390 \
--to=ttaylorr@openai.com \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.com \
--cc=pia@pierre.co \
--cc=stolee@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox