builtin/repack.c: pass `repack_write_midx_opts` to `midx_included_packs`

Instead of passing individual parameters (in this case, "existing", "names", and "geometry") to `midx_included_packs()`, pass a pointer to a `repack_write_midx_opts` structure instead. Besides reducing the number of parameters necessary to call the `midx_included_packs` function, this refactoring sets us up nicely to inline the call to `midx_included_packs()` into `write_midx_included_packs()`, thus making the caller (in this case, `cmd_repack()`) oblivious to the set of packs being written into the MIDX. In order to do this, `repack_write_midx_opts` has to keep track of the set of existing packs, so add an additional field to point to that set. 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:29 UTC f07263fd9fcb6b03f1e1db041269e2d5b85ccff8
1 file changed +8 -5
builtin/repack.c
+8 -5
@@ -108,6 +108,7 @@ static int repack_config(const char *var, const char *value,
108 }
109
110 struct repack_write_midx_opts {
111 + struct existing_packs *existing;
112 struct string_list *include;
113 struct pack_geometry *geometry;
114 struct string_list *names;
@@ -188,10 +189,11 @@ static int midx_has_unknown_packs(struct string_list *include,
189 }
190
191 static void midx_included_packs(struct string_list *include,
191 - struct existing_packs *existing,
192 - struct string_list *names,
193 - struct pack_geometry *geometry)
192 + struct repack_write_midx_opts *opts)
193 {
194 + struct existing_packs *existing = opts->existing;
195 + struct pack_geometry *geometry = opts->geometry;
196 + struct string_list *names = opts->names;
197 struct string_list_item *item;
198 struct strbuf buf = STRBUF_INIT;
199
@@ -242,7 +244,7 @@ static void midx_included_packs(struct string_list *include,
244 }
245 }
246
245 - if (midx_must_contain_cruft ||
247 + if (opts->midx_must_contain_cruft ||
248 midx_has_unknown_packs(include, geometry, existing)) {
249 /*
250 * If there are one or more unknown pack(s) present (see
@@ -994,6 +996,7 @@ int cmd_repack(int argc,
996 if (write_midx) {
997 struct string_list include = STRING_LIST_INIT_DUP;
998 struct repack_write_midx_opts opts = {
999 + .existing = &existing,
1000 .include = &include,
1001 .geometry = &geometry,
1002 .names = &names,
@@ -1003,7 +1006,7 @@ int cmd_repack(int argc,
1006 .write_bitmaps = write_bitmaps > 0,
1007 .midx_must_contain_cruft = midx_must_contain_cruft
1008 };
1006 - midx_included_packs(&include, &existing, &names, &geometry);
1009 + midx_included_packs(&include, &opts);
1010
1011 ret = write_midx_included_packs(&opts);
1012