[PATCH 44/49] builtin/repack.c: pass `write_pack_opts` to `finish_pack_objects_cmd()`

Taylor Blau
2025-09-28T22:10:18Z

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>
---
builtin/repack.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/builtin/repack.c b/builtin/repack.c
index be8e6689fc..8db95305c8 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -108,11 +108,12 @@ static int repack_config(const char *var, const char *value,
}

static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
+ struct write_pack_opts *opts,
struct child_process *cmd,
- struct string_list *names,
- int local)
+ struct string_list *names)
{
FILE *out;
+ int local = write_pack_opts_is_local(opts);
struct strbuf line = STRBUF_INIT;

out = xfdopen(cmd->out, "r");
@@ -128,7 +129,8 @@ static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
*/
if (local) {
item = string_list_append(names, line.buf);
- item->util = generated_pack_populate(line.buf, packtmp);
+ item->util = generated_pack_populate(line.buf,
+ opts->packtmp);
}
}
fclose(out);
@@ -147,7 +149,6 @@ static int write_filtered_pack(struct write_pack_opts *opts,
FILE *in;
int ret;
const char *caret;
- int local = write_pack_opts_is_local(opts);
const char *pack_prefix = write_pack_opts_pack_prefix(opts);

prepare_pack_objects(&cmd, opts->po_args, opts->destination);
@@ -183,8 +184,8 @@ static int write_filtered_pack(struct write_pack_opts *opts,
fprintf(in, "%s%s.pack\n", caret, item->string);
fclose(in);

- return finish_pack_objects_cmd(existing->repo->hash_algo, &cmd, names,
- local);
+ return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
+ names);
}

static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
@@ -231,7 +232,6 @@ static int write_cruft_pack(struct write_pack_opts *opts,
struct string_list_item *item;
FILE *in;
int ret;
- int local = write_pack_opts_is_local(opts);
const char *pack_prefix = write_pack_opts_pack_prefix(opts);

prepare_pack_objects(&cmd, opts->po_args, opts->destination);
@@ -279,8 +279,8 @@ static int write_cruft_pack(struct write_pack_opts *opts,
fprintf(in, "%s.pack\n", item->string);
fclose(in);

- return finish_pack_objects_cmd(existing->repo->hash_algo, &cmd, names,
- local);
+ return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
+ names);
}

int cmd_repack(int argc,
@@ -294,6 +294,7 @@ int cmd_repack(int argc,
struct existing_packs existing = EXISTING_PACKS_INIT;
struct pack_geometry geometry = { 0 };
struct tempfile *refs_snapshot = NULL;
+ struct write_pack_opts opts = { 0 };
int i, ret;
int show_progress;

@@ -560,7 +561,10 @@ int cmd_repack(int argc,
fclose(in);
}

- ret = finish_pack_objects_cmd(repo->hash_algo, &cmd, &names, 1);
+ opts.packdir = packdir;
+ opts.destination = packdir;
+ opts.packtmp = packtmp;
+ ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd, &names);
if (ret)
goto cleanup;

--
2.51.0.243.g16eca91f2c0