Subject: Re: [PATCH 4/5] midx-write: use uint32_t for preferred_pack_idx

From: Junio C Hamano <[email-masked]>
Date: Thu, 28 Aug 2025 13:58:24 -0700

"Derrick Stolee via GitGitGadget" <[email-masked]> writes:

> For now, replace the use of -1 with a 'NO_PREFERRED_PACK' macro and an
> equality check. The macro stores the max value of a uint32_t, so we
> cannot store a preferred pack that appears last in a list of 2^32 total
> packs, but that's expected to be unreasonable already. This improves the
> range from 2^31 already.

;-)  

I very much like this change.  An obvious alternative may be to use
int instead of uint32_t to number and index into in-core packs, as
we all know that not just 2^32 but 2^31 is still unreasonably too
many anyway.

> There are some careful things to worry about with initializing the
> preferred pack in the struct and using that value when searching for a
> preferred pack that was already incorrect but accidentally working when
> the index was initialized to zero.

True.

> -	struct write_midx_context ctx = { 0 };
> +	struct write_midx_context ctx = {
> +		.preferred_pack_idx = NO_PREFERRED_PACK,
> +	 };

Good.

>  	if (preferred_pack_name) {
> -		ctx.preferred_pack_idx = -1;
> +		ctx.preferred_pack_idx = NO_PREFERRED_PACK;

This too.

Thanks.