remote-curl: use argv_array in parse_push()

Use argv_array to build an array of strings instead of open-coding it. This simplifies the code a bit. We also need to make the specs parameter of push(), push_dav() and push_git() const to match the argv member of the argv_array. That's fine, as all three only actually read from the specs array anyway. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 13, 2019 at 15:37 UTC 062a309d360d47a7eff0036b7706dc923fe8081e
1 file changed +9 -13
remote-curl.c
+9 -13
@@ -1154,7 +1154,7 @@ static void parse_fetch(struct strbuf *buf)
1154 strbuf_reset(buf);
1155 }
1156
1157 -static int push_dav(int nr_spec, char **specs)
1157 +static int push_dav(int nr_spec, const char **specs)
1158 {
1159 struct child_process child = CHILD_PROCESS_INIT;
1160 size_t i;
@@ -1175,7 +1175,7 @@ static int push_dav(int nr_spec, char **specs)
1175 return 0;
1176 }
1177
1178 -static int push_git(struct discovery *heads, int nr_spec, char **specs)
1178 +static int push_git(struct discovery *heads, int nr_spec, const char **specs)
1179 {
1180 struct rpc_state rpc;
1181 int i, err;
@@ -1225,7 +1225,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
1225 return err;
1226 }
1227
1228 -static int push(int nr_spec, char **specs)
1228 +static int push(int nr_spec, const char **specs)
1229 {
1230 struct discovery *heads = discover_refs("git-receive-pack", 1);
1231 int ret;
@@ -1240,14 +1240,12 @@ static int push(int nr_spec, char **specs)
1240
1241 static void parse_push(struct strbuf *buf)
1242 {
1243 - char **specs = NULL;
1244 - int alloc_spec = 0, nr_spec = 0, i, ret;
1243 + struct argv_array specs = ARGV_ARRAY_INIT;
1244 + int ret;
1245
1246 do {
1247 - if (starts_with(buf->buf, "push ")) {
1248 - ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
1249 - specs[nr_spec++] = xstrdup(buf->buf + 5);
1250 - }
1247 + if (starts_with(buf->buf, "push "))
1248 + argv_array_push(&specs, buf->buf + 5);
1249 else
1250 die(_("http transport does not support %s"), buf->buf);
1251
@@ -1258,7 +1256,7 @@ static void parse_push(struct strbuf *buf)
1256 break;
1257 } while (1);
1258
1261 - ret = push(nr_spec, specs);
1259 + ret = push(specs.argc, specs.argv);
1260 printf("\n");
1261 fflush(stdout);
1262
@@ -1266,9 +1264,7 @@ static void parse_push(struct strbuf *buf)
1264 exit(128); /* error already reported */
1265
1266 free_specs:
1269 - for (i = 0; i < nr_spec; i++)
1270 - free(specs[i]);
1271 - free(specs);
1267 + argv_array_clear(&specs);
1268 }
1269
1270 static int stateless_connect(const char *service_name)