Skip to content

Commit 4a17e97

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Helped-by: Jeff King <[email protected]> Helped-by: Patrick Steinhardt <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eabfaf8 commit 4a17e97

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

builtin/repack.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ static int has_existing_non_kept_packs(const struct existing_packs *existing)
111111
return existing->non_kept_packs.nr || existing->cruft_packs.nr;
112112
}
113113

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+
114124
static void mark_packs_for_deletion_1(struct string_list *names,
115125
struct string_list *list)
116126
{
@@ -130,7 +140,7 @@ static void mark_packs_for_deletion_1(struct string_list *names,
130140
* (if `-d` was given).
131141
*/
132142
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);
134144
}
135145
}
136146

@@ -158,7 +168,7 @@ static void remove_redundant_packs_1(struct string_list *packs)
158168
{
159169
struct string_list_item *item;
160170
for_each_string_list_item(item, packs) {
161-
if (!((uintptr_t)item->util & DELETE_PACK))
171+
if (!pack_is_marked_for_deletion(item))
162172
continue;
163173
remove_redundant_pack(packdir, item->string);
164174
}
@@ -702,13 +712,13 @@ static void midx_included_packs(struct string_list *include,
702712
}
703713
} else {
704714
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))
706716
continue;
707717
string_list_insert(include, xstrfmt("%s.idx", item->string));
708718
}
709719

710720
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))
712722
continue;
713723
string_list_insert(include, xstrfmt("%s.idx", item->string));
714724
}

0 commit comments

Comments
 (0)