Skip to content

Commit 9a53583

Browse files
ttaylorrgitster
authored andcommitted
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>
1 parent 3758052 commit 9a53583

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

builtin/repack.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ static void prepare_pack_objects(struct child_process *cmd,
339339
cmd->out = -1;
340340
}
341341

342+
struct write_oid_context {
343+
struct child_process *cmd;
344+
const struct git_hash_algo *algop;
345+
};
346+
342347
/*
343348
* Write oid to the given struct child_process's stdin, starting it first if
344349
* necessary.
@@ -347,14 +352,15 @@ static int write_oid(const struct object_id *oid,
347352
struct packed_git *pack UNUSED,
348353
uint32_t pos UNUSED, void *data)
349354
{
350-
struct child_process *cmd = data;
355+
struct write_oid_context *ctx = data;
356+
struct child_process *cmd = ctx->cmd;
351357

352358
if (cmd->in == -1) {
353359
if (start_command(cmd))
354360
die(_("could not start pack-objects to repack promisor objects"));
355361
}
356362

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 ||
358364
write_in_full(cmd->in, "\n", 1) < 0)
359365
die(_("failed to feed promisor objects to pack-objects"));
360366
return 0;
@@ -413,6 +419,7 @@ static void repack_promisor_objects(struct repository *repo,
413419
const struct pack_objects_args *args,
414420
struct string_list *names)
415421
{
422+
struct write_oid_context ctx;
416423
struct child_process cmd = CHILD_PROCESS_INIT;
417424
FILE *out;
418425
struct strbuf line = STRBUF_INIT;
@@ -427,7 +434,9 @@ static void repack_promisor_objects(struct repository *repo,
427434
* {type -> existing pack order} ordering when computing deltas instead
428435
* of a {type -> size} ordering, which may produce better deltas.
429436
*/
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,
431440
FOR_EACH_OBJECT_PROMISOR_ONLY);
432441

433442
if (cmd.in == -1) {

0 commit comments

Comments
 (0)