repack: extract `locate_existing_pack()` helper

Factor out the lookup from `existing_packs_retain_cruft()` that converts a pack basename to a `string_list_item` into a reusable static helper function, `locate_existing_pack()`. A subsequent commit will introduce a new function which will need to perform this same lookup against a different `string_list`. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jun 26, 2026 at 15:02 UTC d65798abb799bdf6915501ca274fc85cbc35d69f
1 file changed +16 -5
repack.c
+16 -5
@@ -226,21 +226,32 @@ static void existing_packs_mark_for_deletion_1(const struct git_hash_algo *algop
226 }
227 }
228
229 -void existing_packs_retain_cruft(struct existing_packs *existing,
230 - struct packed_git *cruft)
229 +static struct string_list_item *locate_existing_pack(struct string_list *list,
230 + struct packed_git *p)
231 {
232 struct strbuf buf = STRBUF_INIT;
233 struct string_list_item *item;
234
235 - strbuf_addstr(&buf, pack_basename(cruft));
235 + strbuf_addstr(&buf, pack_basename(p));
236 strbuf_strip_suffix(&buf, ".pack");
237
238 - item = string_list_lookup(&existing->cruft_packs, buf.buf);
238 + item = string_list_lookup(list, buf.buf);
239 +
240 + strbuf_release(&buf);
241 +
242 + return item;
243 +}
244 +
245 +void existing_packs_retain_cruft(struct existing_packs *existing,
246 + struct packed_git *cruft)
247 +{
248 + struct string_list_item *item;
249 +
250 + item = locate_existing_pack(&existing->cruft_packs, cruft);
251 if (!item)
252 BUG("could not find cruft pack '%s'", pack_basename(cruft));
253
254 existing_packs_mark_retained(item);
243 - strbuf_release(&buf);
255 }
256
257 void existing_packs_mark_for_deletion(struct existing_packs *existing,