remote-curl: simplify passing of push specs

The push specs are kept in a strvec, whose array is NULL-terminated.
Pass only that to the protocol handlers, which avoids dealing with item
counts and their conversions from size_t to int, slightly simplifying
the code.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
René Scharfe 2026-07-15 06:41:17 +02:00 committed by Junio C Hamano
parent 55526a1826
commit f749a83291
1 changed files with 9 additions and 11 deletions

View File

@ -1340,10 +1340,9 @@ static void parse_get(const char *arg)
fflush(stdout); fflush(stdout);
} }


static int push_dav(int nr_spec, const char **specs) static int push_dav(const char **specs)
{ {
struct child_process child = CHILD_PROCESS_INIT; struct child_process child = CHILD_PROCESS_INIT;
size_t i;


child.git_cmd = 1; child.git_cmd = 1;
strvec_push(&child.args, "http-push"); strvec_push(&child.args, "http-push");
@ -1353,15 +1352,14 @@ static int push_dav(int nr_spec, const char **specs)
if (options.verbosity > 1) if (options.verbosity > 1)
strvec_push(&child.args, "--verbose"); strvec_push(&child.args, "--verbose");
strvec_push(&child.args, url.buf); strvec_push(&child.args, url.buf);
for (i = 0; i < nr_spec; i++) strvec_pushv(&child.args, specs);
strvec_push(&child.args, specs[i]);


if (run_command(&child)) if (run_command(&child))
die(_("git-http-push failed")); die(_("git-http-push failed"));
return 0; return 0;
} }


static int push_git(struct discovery *heads, int nr_spec, const char **specs) static int push_git(struct discovery *heads, const char **specs)
{ {
struct rpc_state rpc = RPC_STATE_INIT; struct rpc_state rpc = RPC_STATE_INIT;
int i, err; int i, err;
@ -1400,8 +1398,8 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs)
strvec_push(&args, "--force-if-includes"); strvec_push(&args, "--force-if-includes");


strvec_push(&args, "--stdin"); strvec_push(&args, "--stdin");
for (i = 0; i < nr_spec; i++) for (; *specs; specs++)
packet_buf_write(&preamble, "%s\n", specs[i]); packet_buf_write(&preamble, "%s\n", *specs);
packet_buf_flush(&preamble); packet_buf_flush(&preamble);


memset(&rpc, 0, sizeof(rpc)); memset(&rpc, 0, sizeof(rpc));
@ -1416,15 +1414,15 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs)
return err; return err;
} }


static int push(int nr_spec, const char **specs) static int push(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;


if (heads->proto_git) if (heads->proto_git)
ret = push_git(heads, nr_spec, specs); ret = push_git(heads, specs);
else else
ret = push_dav(nr_spec, specs); ret = push_dav(specs);
free_discovery(heads); free_discovery(heads);
return ret; return ret;
} }
@ -1448,7 +1446,7 @@ static void parse_push(struct strbuf *buf)
break; break;
} while (1); } while (1);


ret = push(specs.nr, specs.v); ret = push(specs.v);
printf("\n"); printf("\n");
fflush(stdout); fflush(stdout);