Re: [PATCH v2 1/4] midx: access pack names through `nth_midxed_pack_name()`
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Jun 3, 2025, 22:23 UTC
- Message-ID
- <aD91yE8rKkjwe3mf@nand.local>
- In-Reply-To
- <xmqqmsavjg3s.fsf@gitster.g>
On Thu, May 29, 2025 at 01:51:03PM -0700, Junio C Hamano wrote:
Show 23 quoted lines
> Taylor Blau <me@ttaylorr.com> writes: > > > Accessing a MIDX's 'pack_names' array is somewhat error-prone when > > dealing with incremental MIDX chains, where the (global) pack_int_id for > > some pack may differ from the containing layer's index for that pack. > > > > Introduce `nth_midxed_pack_name()` in an effort to reduce a common > > source of errors by discouraging external callers from accessing a > > layer's `pack_names` array directly. > > > > Signed-off-by: Taylor Blau <me@ttaylorr.com> > > --- > > midx.c | 7 +++++++ > > midx.h | 2 ++ > > pack-bitmap.c | 4 ++-- > > t/helper/test-read-midx.c | 7 ++++--- > > 4 files changed, 15 insertions(+), 5 deletions(-) > > One thing I forgot to ask. Should we expect that > > $ git grep -E -e '(\.|->)pack_names\[' > > to give hits only from the implementation of nth_midxed_pack_name()?
I waffled on this a bit... and I think the answer is "almost". Certainly callers outside of midx.c or midx-write.c should not be touching "pack_names" directly.
But there are a couple of spots in midx-write.c that are really more convenient to directly look at the pack_names array rather than going through the accessor.
Thanks, Taylor