Subject: Re: [PATCH 01/16] midx-write: handle noop writes when converting incremental chains

From: Taylor Blau <[email-masked]>
Date: Tue, 31 Mar 2026 17:43:11 -0400

On Mon, Mar 30, 2026 at 06:33:46PM -0400, Jeff King wrote:
> Now we iterate through each layer individually. We assume that the total
> count matches ctx->nr, otherwise the midx struct is totally corrupt. We
> could count them and double-check, I guess, but I don't think there's
> much point (it would be a BUG() if they were mismatched).

Yeah, I agree. The omitted context:

        if (ctx->nr != midx->num_packs + midx->num_packs_in_base)
                goto out;

tells us that if we get to this spot, we expect our 'ctx->nr' to be equal
to 'midx->num_packs + midx->num_packs_in_base'.

As soon as we find a non-already-MIDX'd pack, we 'goto out', so I don't
think it makes much sense to build up a count and check it at the end
even after we know we can't optimize out the write.

We could check that the ->num_packs of each of the tip's base MIDXs
match ->num_packs_in_base, but the MIDX internals handle that for us by
how we construct that field, since num_packs_in_base is *not* read from
the on-disk MIDX.

Thanks,
Taylor