Create a new write_oid_hex_cmd() function to send an oid to the standard input of a running command. This new function will be used in a following commit. Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- builtin/repack.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/builtin/repack.c b/builtin/repack.c index 0541c3ce15..e591c295cf 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -182,6 +182,17 @@ static void prepare_pack_objects(struct child_process *cmd, cmd->out = -1; } +static void write_oid_hex_cmd(const char *oid_hex, + struct child_process *cmd, + const char *err_msg) +{ + if (cmd->in == -1 && start_command(cmd)) + die("%s", err_msg); + + xwrite(cmd->in, oid_hex, the_hash_algo->hexsz); + xwrite(cmd->in, "\n", 1); +} + /* * Write oid to the given struct child_process's stdin, starting it first if * necessary. @@ -192,13 +203,8 @@ static int write_oid(const struct object_id *oid, { struct child_process *cmd = data; - if (cmd->in == -1) { - if (start_command(cmd)) - die(_("could not start pack-objects to repack promisor objects")); - } - - xwrite(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz); - xwrite(cmd->in, "\n", 1); + write_oid_hex_cmd(oid_to_hex(oid), cmd, + _("could not start pack-objects to repack promisor objects")); return 0; } -- 2.41.0.37.gae45d9845e