repack: keep track of MIDX pack names using existing_packs

Instead of storing the list of MIDX pack names separately, let's inline it into the existing_packs struct, further reducing the number of parameters we have to pass around. This amounts to adding a new string_list to the existing_packs struct, and populating it via `existing_packs_collect()`. This is fairly straightforward to do, since we are already looping over all packs, all we need to do is: if (p->multi_pack_index) string_list_append(&existing->midx_packs, pack_basename(p)); Note, however, that this check *must* come before other conditions where we discard and do not keep track of a pack, including the condition "if (!p->pack_local)" immediately below. This is because the existing routine which collects MIDX pack names does so blindly, and does not discard, for example, non-local packs. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 15, 2025 at 18:28 UTC 2fee63a71ae8113fd91d8e5924ae4a5619ad0cd3
3 files changed +10 -22
builtin/repack.c
+4 -22
@@ -118,8 +118,7 @@ struct repack_write_midx_opts {
118 int midx_must_contain_cruft;
119 };
120
121 -static int midx_has_unknown_packs(struct string_list *midx_pack_names,
122 - struct string_list *include,
121 +static int midx_has_unknown_packs(struct string_list *include,
122 struct pack_geometry *geometry,
123 struct existing_packs *existing)
124 {
@@ -127,7 +126,7 @@ static int midx_has_unknown_packs(struct string_list *midx_pack_names,
126
127 string_list_sort(include);
128
130 - for_each_string_list_item(item, midx_pack_names) {
129 + for_each_string_list_item(item, &existing->midx_packs) {
130 const char *pack_name = item->string;
131
132 /*
@@ -190,7 +189,6 @@ static int midx_has_unknown_packs(struct string_list *midx_pack_names,
189
190 static void midx_included_packs(struct string_list *include,
191 struct existing_packs *existing,
193 - struct string_list *midx_pack_names,
192 struct string_list *names,
193 struct pack_geometry *geometry)
194 {
@@ -245,8 +243,7 @@ static void midx_included_packs(struct string_list *include,
243 }
244
245 if (midx_must_contain_cruft ||
248 - midx_has_unknown_packs(midx_pack_names, include, geometry,
249 - existing)) {
246 + midx_has_unknown_packs(include, geometry, existing)) {
247 /*
248 * If there are one or more unknown pack(s) present (see
249 * midx_has_unknown_packs() for what makes a pack
@@ -604,7 +601,6 @@ int cmd_repack(int argc,
601 struct child_process cmd = CHILD_PROCESS_INIT;
602 struct string_list_item *item;
603 struct string_list names = STRING_LIST_INIT_DUP;
607 - struct string_list midx_pack_names = STRING_LIST_INIT_DUP;
604 struct existing_packs existing = EXISTING_PACKS_INIT;
605 struct pack_geometry geometry = { 0 };
606 struct tempfile *refs_snapshot = NULL;
@@ -978,18 +974,6 @@ int cmd_repack(int argc,
974
975 string_list_sort(&names);
976
981 - if (get_multi_pack_index(repo->objects->sources)) {
982 - struct multi_pack_index *m =
983 - get_multi_pack_index(repo->objects->sources);
984 -
985 - for (; m; m = m->base_midx) {
986 - for (uint32_t i = 0; i < m->num_packs; i++) {
987 - string_list_append(&midx_pack_names,
988 - m->pack_names[i]);
989 - }
990 - }
991 - }
992 -
977 close_object_store(repo->objects);
978
979 /*
@@ -1015,8 +999,7 @@ int cmd_repack(int argc,
999 .write_bitmaps = write_bitmaps > 0,
1000 .midx_must_contain_cruft = midx_must_contain_cruft
1001 };
1018 - midx_included_packs(&include, &existing, &midx_pack_names,
1019 - &names, &geometry);
1002 + midx_included_packs(&include, &existing, &names, &geometry);
1003
1004 ret = write_midx_included_packs(&opts);
1005
@@ -1063,7 +1046,6 @@ int cmd_repack(int argc,
1046 cleanup:
1047 string_list_clear(&keep_pack_list, 0);
1048 string_list_clear(&names, 1);
1066 - string_list_clear(&midx_pack_names, 0);
1049 existing_packs_release(&existing);
1050 pack_geometry_release(&geometry);
1051 pack_objects_args_release(&po_args);
repack.c
+5
@@ -80,6 +80,9 @@ void existing_packs_collect(struct existing_packs *existing,
80 size_t i;
81 const char *base;
82
83 + if (p->multi_pack_index)
84 + string_list_append(&existing->midx_packs,
85 + pack_basename(p));
86 if (!p->pack_local)
87 continue;
88
@@ -104,6 +107,7 @@ void existing_packs_collect(struct existing_packs *existing,
107 string_list_sort(&existing->kept_packs);
108 string_list_sort(&existing->non_kept_packs);
109 string_list_sort(&existing->cruft_packs);
110 + string_list_sort(&existing->midx_packs);
111 strbuf_release(&buf);
112 }
113
@@ -220,6 +224,7 @@ void existing_packs_release(struct existing_packs *existing)
224 string_list_clear(&existing->kept_packs, 0);
225 string_list_clear(&existing->non_kept_packs, 0);
226 string_list_clear(&existing->cruft_packs, 0);
227 + string_list_clear(&existing->midx_packs, 0);
228 }
229
230 static struct {
repack.h
+1
@@ -40,6 +40,7 @@ struct existing_packs {
40 struct string_list kept_packs;
41 struct string_list non_kept_packs;
42 struct string_list cruft_packs;
43 + struct string_list midx_packs;
44 };
45
46 #define EXISTING_PACKS_INIT { \