]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/repack.c: avoid "the_hash_algo" when deleting packs
authorTaylor Blau <me@ttaylorr.com>
Wed, 15 Oct 2025 22:27:33 +0000 (18:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Oct 2025 17:08:53 +0000 (10:08 -0700)
The "mark_packs_for_deletion_1" function uses "the_hash_algo->hexsz" to
isolate a pack's checksum before deleting it to avoid deleting a newly
written pack having the same checksum (that is, some generated pack
wound up identical to an existing pack).

Avoid this by passing down a "struct git_hash_algo" pointer, and refer to
the hash algorithm through it instead.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/repack.c

index 4f08b57ddbde0ff60101fab5bb282e489b315118..094f5a0cc26d57a1857d22ff2661e92a87b54ae1 100644 (file)
@@ -168,11 +168,12 @@ static int pack_is_retained(struct string_list_item *item)
        return (uintptr_t)item->util & RETAIN_PACK;
 }
 
-static void mark_packs_for_deletion_1(struct string_list *names,
+static void mark_packs_for_deletion_1(const struct git_hash_algo *algop,
+                                     struct string_list *names,
                                      struct string_list *list)
 {
        struct string_list_item *item;
-       const int hexsz = the_hash_algo->hexsz;
+       const int hexsz = algop->hexsz;
 
        for_each_string_list_item(item, list) {
                char *sha1;
@@ -217,8 +218,9 @@ static void mark_packs_for_deletion(struct existing_packs *existing,
                                    struct string_list *names)
 
 {
-       mark_packs_for_deletion_1(names, &existing->non_kept_packs);
-       mark_packs_for_deletion_1(names, &existing->cruft_packs);
+       const struct git_hash_algo *algop = existing->repo->hash_algo;
+       mark_packs_for_deletion_1(algop, names, &existing->non_kept_packs);
+       mark_packs_for_deletion_1(algop, names, &existing->cruft_packs);
 }
 
 static void remove_redundant_pack(struct repository *repo,