Re: [PATCH 4/5] midx-write: use uint32_t for preferred_pack_idx
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 28, 2025, 20:58 UTC
- Message-ID
- <xmqqsehbtb7z.fsf@gitster.g>
- In-Reply-To
- <bd97db26f7f789315134dc796403b1ab9976135b.1756402795.git.gitgitgadget@gmail.com>
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> 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.