Subject: Re: [PATCH v2 2/2] midx: stop repeatedly looking up nonexistent packfiles

From: Junio C Hamano <[email-masked]>
Date: Thu, 22 May 2025 11:44:43 -0700

Jeff King <[email-masked]> writes:

> But back in the caller...
>
>> 	p = m->packs[pack_int_id - m->num_packs_in_base];
>> ...
>
> Our pack_int_id is the global one, so it needs to be adjusted. But this
> pack pointer we access is the same one that was filled (or not) by
> prepare_midx_pack(). So it cannot be NULL or the magic "fails" value,
> because prepare_midx_pack() returned 0.
>
> So I think this code is fine.

Ahh, I missed that call to midx_for_pack() in prepare_midx_pack()
that modifies pack_int_id variable.  Of course, it did not help that
the implementation detail of adjusting by m->num_packs_in_base which
is done in midx_for_pack() is not abstracted out and the caller needs
to do the same as above.  That confused me.

Thanks for an explanation.