builtin/repack.c: avoid directly inspecting "util"

The `->util` field corresponding to each string_list_item is used to track the existence of some pack at the beginning of a repack operation was originally intended to be used as a bitfield. This bitfield tracked: - (1 << 0): whether or not the pack should be deleted - (1 << 1): whether or not the pack is cruft The previous commit removed the use of the second bit, but a future patch (from a different series than this one) will introduce a new use of it. So we could stop treating the util pointer as a bitfield and instead start treating it as if it were a boolean. But this would require some backtracking when that later patch is applied. Instead, let's avoid touching the ->util field directly, and instead introduce convenience functions like: - pack_mark_for_deletion() - pack_is_marked_for_deletion() Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Jeff King <peff@peff.net> Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Sep 13, 2023 at 15:18 UTC 4a17e97246470049b8bde5be0d767ef66e550555
1 file changed +14 -4
builtin/repack.c
+14 -4
@@ -111,6 +111,16 @@ static int has_existing_non_kept_packs(const struct existing_packs *existing)
111 return existing->non_kept_packs.nr || existing->cruft_packs.nr;
112 }
113
114 +static void pack_mark_for_deletion(struct string_list_item *item)
115 +{
116 + item->util = (void*)((uintptr_t)item->util | DELETE_PACK);
117 +}
118 +
119 +static int pack_is_marked_for_deletion(struct string_list_item *item)
120 +{
121 + return (uintptr_t)item->util & DELETE_PACK;
122 +}
123 +
124 static void mark_packs_for_deletion_1(struct string_list *names,
125 struct string_list *list)
126 {
@@ -130,7 +140,7 @@ static void mark_packs_for_deletion_1(struct string_list *names,
140 * (if `-d` was given).
141 */
142 if (!string_list_has_string(names, sha1))
133 - item->util = (void*)(uintptr_t)((size_t)item->util | DELETE_PACK);
143 + pack_mark_for_deletion(item);
144 }
145 }
146
@@ -158,7 +168,7 @@ static void remove_redundant_packs_1(struct string_list *packs)
168 {
169 struct string_list_item *item;
170 for_each_string_list_item(item, packs) {
161 - if (!((uintptr_t)item->util & DELETE_PACK))
171 + if (!pack_is_marked_for_deletion(item))
172 continue;
173 remove_redundant_pack(packdir, item->string);
174 }
@@ -702,13 +712,13 @@ static void midx_included_packs(struct string_list *include,
712 }
713 } else {
714 for_each_string_list_item(item, &existing->non_kept_packs) {
705 - if ((uintptr_t)item->util & DELETE_PACK)
715 + if (pack_is_marked_for_deletion(item))
716 continue;
717 string_list_insert(include, xstrfmt("%s.idx", item->string));
718 }
719
720 for_each_string_list_item(item, &existing->cruft_packs) {
711 - if ((uintptr_t)item->util & DELETE_PACK)
721 + if (pack_is_marked_for_deletion(item))
722 continue;
723 string_list_insert(include, xstrfmt("%s.idx", item->string));
724 }