Skip to content

Commit 36857e0

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 28bf942 commit 36857e0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

builtin/replace.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,17 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
193193
*/
194194
static void export_object(const unsigned char *sha1, const char *filename)
195195
{
196-
const char *argv[] = { "--no-replace-objects", "cat-file", "-p", NULL, NULL };
197-
struct child_process cmd = { argv };
196+
struct child_process cmd = { NULL };
198197
int fd;
199198

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

204-
argv[3] = sha1_to_hex(sha1);
203+
argv_array_push(&cmd.args, "--no-replace-objects");
204+
argv_array_push(&cmd.args, "cat-file");
205+
argv_array_push(&cmd.args, "-p");
206+
argv_array_push(&cmd.args, sha1_to_hex(sha1));
205207
cmd.git_cmd = 1;
206208
cmd.out = fd;
207209

0 commit comments

Comments
 (0)