builtin/repack.c: avoid "the_hash_algo" in `write_oid()`

In a similar spirit as the previous commit, avoid referring directly to "the_hash_algo" within builtin/repack.c::write_oid(). Unlike the previous commit, we are within a callback function, so must introduce a new struct to pass additional data through its "data" pointer. 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:27 UTC 9a53583b77c35576f87b7e29cb109b46d29ad803
1 file changed +12 -3
builtin/repack.c
+12 -3
@@ -339,6 +339,11 @@ static void prepare_pack_objects(struct child_process *cmd,
339 cmd->out = -1;
340 }
341
342 +struct write_oid_context {
343 + struct child_process *cmd;
344 + const struct git_hash_algo *algop;
345 +};
346 +
347 /*
348 * Write oid to the given struct child_process's stdin, starting it first if
349 * necessary.
@@ -347,14 +352,15 @@ static int write_oid(const struct object_id *oid,
352 struct packed_git *pack UNUSED,
353 uint32_t pos UNUSED, void *data)
354 {
350 - struct child_process *cmd = data;
355 + struct write_oid_context *ctx = data;
356 + struct child_process *cmd = ctx->cmd;
357
358 if (cmd->in == -1) {
359 if (start_command(cmd))
360 die(_("could not start pack-objects to repack promisor objects"));
361 }
362
357 - if (write_in_full(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
363 + if (write_in_full(cmd->in, oid_to_hex(oid), ctx->algop->hexsz) < 0 ||
364 write_in_full(cmd->in, "\n", 1) < 0)
365 die(_("failed to feed promisor objects to pack-objects"));
366 return 0;
@@ -413,6 +419,7 @@ static void repack_promisor_objects(struct repository *repo,
419 const struct pack_objects_args *args,
420 struct string_list *names)
421 {
422 + struct write_oid_context ctx;
423 struct child_process cmd = CHILD_PROCESS_INIT;
424 FILE *out;
425 struct strbuf line = STRBUF_INIT;
@@ -427,7 +434,9 @@ static void repack_promisor_objects(struct repository *repo,
434 * {type -> existing pack order} ordering when computing deltas instead
435 * of a {type -> size} ordering, which may produce better deltas.
436 */
430 - for_each_packed_object(repo, write_oid, &cmd,
437 + ctx.cmd = &cmd;
438 + ctx.algop = repo->hash_algo;
439 + for_each_packed_object(repo, write_oid, &ctx,
440 FOR_EACH_OBJECT_PROMISOR_ONLY);
441
442 if (cmd.in == -1) {