1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-10 06:26:13 +02:00

replace: use argv_array in export_object

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>
This commit is contained in:
Jeff King 2014-06-24 05:46:05 -04:00 committed by Junio C Hamano
parent 28bf9429ef
commit 36857e0026

View File

@ -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;