Merge branch 'rs/remote-curl-use-argv-array'

Code cleanup.

* rs/remote-curl-use-argv-array:
  remote-curl: use argv_array in parse_push()
This commit is contained in:
Junio C Hamano 2019-10-18 11:40:50 +09:00
commit 90e0d167c6

View File

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