builtin/repack.c: pass `write_pack_opts` to `finish_pack_objects_cmd()`

To prepare to move the `finish_pack_objects_cmd()` function out of the builtin and into the repack.h API, there are a couple of things we need to do first: - First, let's take advantage of `write_pack_opts_is_local()` function introduced in the previous commit instead of passing "local" explicitly. - Let's also avoid referring to the static 'packtmp' field within builtin/repack.c by instead accessing it through the write_pack_opts argument. There are three callers which need to adjust themselves in order to account for this change. The callers which reside in write_cruft_pack() and write_filtered_pack() both already have an "opts" in scope, so they can pass it through transparently. The other call (at the bottom of `cmd_repack()`) needs to initialize its own write_pack_opts to pass the necessary fields over to the direct call to `finish_pack_objects_cmd()`. 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 80db3cd18985609340f40b2b06f4ef9f86a2cbe0
1 file changed +20 -12
builtin/repack.c
+20 -12
@@ -108,11 +108,12 @@ static int repack_config(const char *var, const char *value,
108 }
109
110 static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
111 + const struct write_pack_opts *opts,
112 struct child_process *cmd,
112 - struct string_list *names,
113 - int local)
113 + struct string_list *names)
114 {
115 FILE *out;
116 + bool local = write_pack_opts_is_local(opts);
117 struct strbuf line = STRBUF_INIT;
118
119 out = xfdopen(cmd->out, "r");
@@ -128,7 +129,8 @@ static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
129 */
130 if (local) {
131 item = string_list_append(names, line.buf);
131 - item->util = generated_pack_populate(line.buf, packtmp);
132 + item->util = generated_pack_populate(line.buf,
133 + opts->packtmp);
134 }
135 }
136 fclose(out);
@@ -147,7 +149,6 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
149 FILE *in;
150 int ret;
151 const char *caret;
150 - bool local = write_pack_opts_is_local(opts);
152 const char *pack_prefix = write_pack_opts_pack_prefix(opts);
153
154 prepare_pack_objects(&cmd, opts->po_args, opts->destination);
@@ -183,8 +184,8 @@ static int write_filtered_pack(const struct write_pack_opts *opts,
184 fprintf(in, "%s%s.pack\n", caret, item->string);
185 fclose(in);
186
186 - return finish_pack_objects_cmd(existing->repo->hash_algo, &cmd, names,
187 - local);
187 + return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
188 + names);
189 }
190
191 static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
@@ -231,7 +232,6 @@ static int write_cruft_pack(const struct write_pack_opts *opts,
232 struct string_list_item *item;
233 FILE *in;
234 int ret;
234 - bool local = write_pack_opts_is_local(opts);
235 const char *pack_prefix = write_pack_opts_pack_prefix(opts);
236
237 prepare_pack_objects(&cmd, opts->po_args, opts->destination);
@@ -279,8 +279,8 @@ static int write_cruft_pack(const struct write_pack_opts *opts,
279 fprintf(in, "%s.pack\n", item->string);
280 fclose(in);
281
282 - return finish_pack_objects_cmd(existing->repo->hash_algo, &cmd, names,
283 - local);
282 + return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
283 + names);
284 }
285
286 int cmd_repack(int argc,
@@ -560,9 +560,17 @@ int cmd_repack(int argc,
560 fclose(in);
561 }
562
563 - ret = finish_pack_objects_cmd(repo->hash_algo, &cmd, &names, 1);
564 - if (ret)
565 - goto cleanup;
563 + {
564 + struct write_pack_opts opts = {
565 + .packdir = packdir,
566 + .destination = packdir,
567 + .packtmp = packtmp,
568 + };
569 + ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd,
570 + &names);
571 + if (ret)
572 + goto cleanup;
573 + }
574
575 if (!names.nr) {
576 if (!po_args.quiet)