get_exporter: use argv_array
This simplifies the code and avoids a fixed array size that we might accidentally overflow. It also prevents a leak after finish_command is run, by using the argv_array that run-command manages for us. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 15, 2014 at 04:34 UTC
2aeae40a754ed8296df95df263e694ad4eab3a49
1 file changed
+10
-16
transport-helper.c
+10
-16
@@ -418,30 +418,24 @@ static int get_exporter(struct transport *transport,
418
{
419
struct helper_data *data = transport->data;
420
struct child_process *helper = get_helper(transport);
421
- int argc = 0, i;
422
- struct strbuf tmp = STRBUF_INIT;
421
+ int i;
422
423
memset(fastexport, 0, sizeof(*fastexport));
424
425
/* we need to duplicate helper->in because we want to use it after
426
* fastexport is done with it. */
427
fastexport->out = dup(helper->in);
429
- fastexport->argv = xcalloc(6 + revlist_args->nr, sizeof(*fastexport->argv));
430
- fastexport->argv[argc++] = "fast-export";
431
- fastexport->argv[argc++] = "--use-done-feature";
432
- fastexport->argv[argc++] = data->signed_tags ?
433
- "--signed-tags=verbatim" : "--signed-tags=warn-strip";
434
- if (data->export_marks) {
435
- strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks);
436
- fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
437
- }
438
- if (data->import_marks) {
439
- strbuf_addf(&tmp, "--import-marks=%s", data->import_marks);
440
- fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
441
- }
428
+ argv_array_push(&fastexport->args, "fast-export");
429
+ argv_array_push(&fastexport->args, "--use-done-feature");
430
+ argv_array_push(&fastexport->args, data->signed_tags ?
431
+ "--signed-tags=verbatim" : "--signed-tags=warn-strip");
432
+ if (data->export_marks)
433
+ argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks);
434
+ if (data->import_marks)
435
+ argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks);
436
437
for (i = 0; i < revlist_args->nr; i++)
444
- fastexport->argv[argc++] = revlist_args->items[i].string;
438
+ argv_array_push(&fastexport->args, revlist_args->items[i].string);
439
440
fastexport->git_cmd = 1;
441
return start_command(fastexport);