]> Kevux Git Server - rit/commit
midx-write: use uint32_t for preferred_pack_idx
authorDerrick Stolee <stolee@gmail.com>
Fri, 5 Sep 2025 19:26:16 +0000 (19:26 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Sep 2025 19:32:01 +0000 (12:32 -0700)
commit68383ac9d4c90c9b3c7591aa0118d72489599b11
tree2b98e26c2029ea0c4dec70ec721564f54381a1d0
parent9c2262d65dee8c1e3656b01f7db0660181902d2a
midx-write: use uint32_t for preferred_pack_idx

midx-write.c has the DISABLE_SIGN_COMPARE_WARNINGS macro defined for a
few reasons, but the biggest one is the use of a signed
preferred_pack_idx member inside the write_midx_context struct. The code
currently uses -1 to indicate an unset preferred pack but pack int ids
are normally handled as uint32_t. There are also a few loops that search
for the preferred pack by name and those iterators will need updates to
uint32_t in the next change.

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. Furthermore, with
this change we end up extending the range from 2^31 possible packs to
2^32-1.

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.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx-write.c