summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-05-15 08:34:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-05-15 16:49:11 (GMT)
commit2aeae40a754ed8296df95df263e694ad4eab3a49 (patch)
tree70b62cacad19968cf201b7804a37553274767ef8
parente0ab2ac6c553cbba5d0275cfd35beb3351cae034 (diff)
downloadgit-2aeae40a754ed8296df95df263e694ad4eab3a49.zip
git-2aeae40a754ed8296df95df263e694ad4eab3a49.tar.gz
git-2aeae40a754ed8296df95df263e694ad4eab3a49.tar.bz2
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>
-rw-r--r--transport-helper.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/transport-helper.c b/transport-helper.c
index fefd34f..9f8f3b1 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -418,30 +418,24 @@ static int get_exporter(struct transport *transport,
{
struct helper_data *data = transport->data;
struct child_process *helper = get_helper(transport);
- int argc = 0, i;
- struct strbuf tmp = STRBUF_INIT;
+ int i;
memset(fastexport, 0, sizeof(*fastexport));
/* we need to duplicate helper->in because we want to use it after
* fastexport is done with it. */
fastexport->out = dup(helper->in);
- fastexport->argv = xcalloc(6 + revlist_args->nr, sizeof(*fastexport->argv));
- fastexport->argv[argc++] = "fast-export";
- fastexport->argv[argc++] = "--use-done-feature";
- fastexport->argv[argc++] = data->signed_tags ?
- "--signed-tags=verbatim" : "--signed-tags=warn-strip";
- if (data->export_marks) {
- strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks);
- fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
- }
- if (data->import_marks) {
- strbuf_addf(&tmp, "--import-marks=%s", data->import_marks);
- fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
- }
+ argv_array_push(&fastexport->args, "fast-export");
+ argv_array_push(&fastexport->args, "--use-done-feature");
+ argv_array_push(&fastexport->args, data->signed_tags ?
+ "--signed-tags=verbatim" : "--signed-tags=warn-strip");
+ if (data->export_marks)
+ argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks);
+ if (data->import_marks)
+ argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks);
for (i = 0; i < revlist_args->nr; i++)
- fastexport->argv[argc++] = revlist_args->items[i].string;
+ argv_array_push(&fastexport->args, revlist_args->items[i].string);
fastexport->git_cmd = 1;
return start_command(fastexport);