Skip to content

Commit

Permalink
replace: use argv_array in export_object
Browse files Browse the repository at this point in the history
This is a little more verbose, but will make it easier to
make parts of our command-line conditional (without
resorting to magic numbers or lots of NULLs to get an
appropriately sized argv array).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 25, 2014
1 parent 28bf942 commit 36857e0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions builtin/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,17 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
*/
static void export_object(const unsigned char *sha1, const char *filename)
{
const char *argv[] = { "--no-replace-objects", "cat-file", "-p", NULL, NULL };
struct child_process cmd = { argv };
struct child_process cmd = { NULL };
int fd;

fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
die_errno("unable to open %s for writing", filename);

argv[3] = sha1_to_hex(sha1);
argv_array_push(&cmd.args, "--no-replace-objects");
argv_array_push(&cmd.args, "cat-file");
argv_array_push(&cmd.args, "-p");
argv_array_push(&cmd.args, sha1_to_hex(sha1));
cmd.git_cmd = 1;
cmd.out = fd;

Expand Down

0 comments on commit 36857e0

Please sign in to comment.