]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote-curl: use argv_array in parse_push()
authorRené Scharfe <l.s.r@web.de>
Sun, 13 Oct 2019 13:37:39 +0000 (15:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Oct 2019 01:55:11 +0000 (10:55 +0900)
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>
remote-curl.c

index 051f26629d7b9f6679e47f6dc353f09c16c377ae..1612e7f52d7930ea2d5fdb0a3df876a597694463 100644 (file)
@@ -1154,7 +1154,7 @@ static void parse_fetch(struct strbuf *buf)
        strbuf_reset(buf);
 }
 
-static int push_dav(int nr_spec, char **specs)
+static int push_dav(int nr_spec, const char **specs)
 {
        struct child_process child = CHILD_PROCESS_INIT;
        size_t i;
@@ -1175,7 +1175,7 @@ static int push_dav(int nr_spec, char **specs)
        return 0;
 }
 
-static int push_git(struct discovery *heads, int nr_spec, char **specs)
+static int push_git(struct discovery *heads, int nr_spec, const char **specs)
 {
        struct rpc_state rpc;
        int i, err;
@@ -1225,7 +1225,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
        return err;
 }
 
-static int push(int nr_spec, char **specs)
+static int push(int nr_spec, const char **specs)
 {
        struct discovery *heads = discover_refs("git-receive-pack", 1);
        int ret;
@@ -1240,14 +1240,12 @@ static int push(int nr_spec, char **specs)
 
 static void parse_push(struct strbuf *buf)
 {
-       char **specs = NULL;
-       int alloc_spec = 0, nr_spec = 0, i, ret;
+       struct argv_array specs = ARGV_ARRAY_INIT;
+       int ret;
 
        do {
-               if (starts_with(buf->buf, "push ")) {
-                       ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
-                       specs[nr_spec++] = xstrdup(buf->buf + 5);
-               }
+               if (starts_with(buf->buf, "push "))
+                       argv_array_push(&specs, buf->buf + 5);
                else
                        die(_("http transport does not support %s"), buf->buf);
 
@@ -1258,7 +1256,7 @@ static void parse_push(struct strbuf *buf)
                        break;
        } while (1);
 
-       ret = push(nr_spec, specs);
+       ret = push(specs.argc, specs.argv);
        printf("\n");
        fflush(stdout);
 
@@ -1266,9 +1264,7 @@ static void parse_push(struct strbuf *buf)
                exit(128); /* error already reported */
 
  free_specs:
-       for (i = 0; i < nr_spec; i++)
-               free(specs[i]);
-       free(specs);
+       argv_array_clear(&specs);
 }
 
 static int stateless_connect(const char *service_name)