]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: extract `locate_existing_pack()` helper
authorTaylor Blau <me@ttaylorr.com>
Fri, 26 Jun 2026 19:02:17 +0000 (15:02 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Jun 2026 21:54:54 +0000 (14:54 -0700)
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>
repack.c

index 571dabb665ee9b7a5ba7810219b4925dd2b574b6..986c74ac7e8c0d1242e4bca2790aba269dda754c 100644 (file)
--- a/repack.c
+++ b/repack.c
@@ -226,21 +226,32 @@ static void existing_packs_mark_for_deletion_1(const struct git_hash_algo *algop
        }
 }
 
-void existing_packs_retain_cruft(struct existing_packs *existing,
-                                struct packed_git *cruft)
+static struct string_list_item *locate_existing_pack(struct string_list *list,
+                                                    struct packed_git *p)
 {
        struct strbuf buf = STRBUF_INIT;
        struct string_list_item *item;
 
-       strbuf_addstr(&buf, pack_basename(cruft));
+       strbuf_addstr(&buf, pack_basename(p));
        strbuf_strip_suffix(&buf, ".pack");
 
-       item = string_list_lookup(&existing->cruft_packs, buf.buf);
+       item = string_list_lookup(list, buf.buf);
+
+       strbuf_release(&buf);
+
+       return item;
+}
+
+void existing_packs_retain_cruft(struct existing_packs *existing,
+                                struct packed_git *cruft)
+{
+       struct string_list_item *item;
+
+       item = locate_existing_pack(&existing->cruft_packs, cruft);
        if (!item)
                BUG("could not find cruft pack '%s'", pack_basename(cruft));
 
        existing_packs_mark_retained(item);
-       strbuf_release(&buf);
 }
 
 void existing_packs_mark_for_deletion(struct existing_packs *existing,