{"thread":{"id":"52030","subject":"[PATCH] remote-curl: use argv_array in parse_push()","startedAt":"2019-10-13T13:39:01Z","lastAt":"2019-10-13T13:39:01Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"383994","messageId":"f0eda0fb-7aae-cd64-194e-44a66eabd225@web.de","threadId":"52030","inReplyTo":null,"subject":"[PATCH] remote-curl: use argv_array in parse_push()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-10-13T13:37:39Z","receivedAt":"2019-10-13T13:39:01Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use argv_array to build an array of strings instead of open-coding it.\nThis simplifies the code a bit.\n\nWe also need to make the specs parameter of push(), push_dav() and\npush_git() const to match the argv member of the argv_array.  That's\nfine, as all three only actually read from the specs array anyway.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n remote-curl.c | 22 +++++++++-------------\n 1 file changed, 9 insertions(+), 13 deletions(-)\n\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 051f26629d..1612e7f52d 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -1154,7 +1154,7 @@ static void parse_fetch(struct strbuf *buf)\n \tstrbuf_reset(buf);\n }\n\n-static int push_dav(int nr_spec, char **specs)\n+static int push_dav(int nr_spec, const char **specs)\n {\n \tstruct child_process child = CHILD_PROCESS_INIT;\n \tsize_t i;\n@@ -1175,7 +1175,7 @@ static int push_dav(int nr_spec, char **specs)\n \treturn 0;\n }\n\n-static int push_git(struct discovery *heads, int nr_spec, char **specs)\n+static int push_git(struct discovery *heads, int nr_spec, const char **specs)\n {\n \tstruct rpc_state rpc;\n \tint i, err;\n@@ -1225,7 +1225,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)\n \treturn err;\n }\n\n-static int push(int nr_spec, char **specs)\n+static int push(int nr_spec, const char **specs)\n {\n \tstruct discovery *heads = discover_refs(\"git-receive-pack\", 1);\n \tint ret;\n@@ -1240,14 +1240,12 @@ static int push(int nr_spec, char **specs)\n\n static void parse_push(struct strbuf *buf)\n {\n-\tchar **specs = NULL;\n-\tint alloc_spec = 0, nr_spec = 0, i, ret;\n+\tstruct argv_array specs = ARGV_ARRAY_INIT;\n+\tint ret;\n\n \tdo {\n-\t\tif (starts_with(buf->buf, \"push \")) {\n-\t\t\tALLOC_GROW(specs, nr_spec + 1, alloc_spec);\n-\t\t\tspecs[nr_spec++] = xstrdup(buf->buf + 5);\n-\t\t}\n+\t\tif (starts_with(buf->buf, \"push \"))\n+\t\t\targv_array_push(&specs, buf->buf + 5);\n \t\telse\n \t\t\tdie(_(\"http transport does not support %s\"), buf->buf);\n\n@@ -1258,7 +1256,7 @@ static void parse_push(struct strbuf *buf)\n \t\t\tbreak;\n \t} while (1);\n\n-\tret = push(nr_spec, specs);\n+\tret = push(specs.argc, specs.argv);\n \tprintf(\"\\n\");\n \tfflush(stdout);\n\n@@ -1266,9 +1264,7 @@ static void parse_push(struct strbuf *buf)\n \t\texit(128); /* error already reported */\n\n  free_specs:\n-\tfor (i = 0; i < nr_spec; i++)\n-\t\tfree(specs[i]);\n-\tfree(specs);\n+\targv_array_clear(&specs);\n }\n\n static int stateless_connect(const char *service_name)\n--\n2.23.0\n"}]}