]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: unconditionally exclude non-kept packs
authorTaylor Blau <me@ttaylorr.com>
Fri, 26 Jun 2026 19:02:13 +0000 (15:02 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Jun 2026 21:54:54 +0000 (14:54 -0700)
In `write_cruft_pack()`, we handle excluding objects found in non-kept
packs from being included in the cruft pack via two code paths:

 * When using '--combine-cruft-below-size' (provided that we are not
   expiring cruft objects), we use the aptly-named
   `combine_small_cruft_packs()` function.

 * In all other cases, we handle it directly in the 'else' branch of the
   same conditional.

Simplify this by moving the non-kept pack exclusion out of the
conditional entirely, so that non-kept packs are always excluded
regardless of whether we are combining small cruft packs or not.

This is a preparatory refactor for a subsequent change that will use the
pack_geometry struct when available to determine which non-kept packs to
exclude.

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

index 0653e88792332eb7f26eb5df81afc497256f583b..6a040e980173a144f3e8488c0ff0b6f76c7106a7 100644 (file)
@@ -9,7 +9,6 @@ static void combine_small_cruft_packs(FILE *in, off_t combine_cruft_below_size,
 {
        struct packed_git *p;
        struct strbuf buf = STRBUF_INIT;
-       size_t i;
 
        repo_for_each_pack(existing->repo, p) {
                if (!(p->is_cruft && p->pack_local))
@@ -30,10 +29,6 @@ static void combine_small_cruft_packs(FILE *in, off_t combine_cruft_below_size,
                }
        }
 
-       for (i = 0; i < existing->non_kept_packs.nr; i++)
-               fprintf(in, "-%s.pack\n",
-                       existing->non_kept_packs.items[i].string);
-
        strbuf_release(&buf);
 }
 
@@ -80,15 +75,14 @@ int write_cruft_pack(const struct write_pack_opts *opts,
        in = xfdopen(cmd.in, "w");
        for_each_string_list_item(item, names)
                fprintf(in, "%s-%s.pack\n", pack_prefix, item->string);
-       if (combine_cruft_below_size && !cruft_expiration) {
+       if (combine_cruft_below_size && !cruft_expiration)
                combine_small_cruft_packs(in, combine_cruft_below_size,
                                          existing);
-       } else {
-               for_each_string_list_item(item, &existing->non_kept_packs)
-                       fprintf(in, "-%s.pack\n", item->string);
+       else
                for_each_string_list_item(item, &existing->cruft_packs)
                        fprintf(in, "-%s.pack\n", item->string);
-       }
+       for_each_string_list_item(item, &existing->non_kept_packs)
+               fprintf(in, "-%s.pack\n", item->string);
        for_each_string_list_item(item, &existing->kept_packs)
                fprintf(in, "%s.pack\n", item->string);
        fclose(in);