Skip to content

Commit 8150749

Browse files
grnchgitster
authored andcommitted
remote-curl: send the refs to fetch-pack on stdin
Now that we can throw an arbitrary number of refs at fetch-pack using its --stdin option, we use it in the remote-curl helper to bypass the OS command line length limit. Signed-off-by: Ivan Todoroski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 078b895 commit 8150749

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

remote-curl.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ static void output_refs(struct ref *refs)
290290
struct rpc_state {
291291
const char *service_name;
292292
const char **argv;
293+
struct strbuf *stdin_preamble;
293294
char *service_url;
294295
char *hdr_content_type;
295296
char *hdr_accept;
@@ -535,6 +536,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
535536
{
536537
const char *svc = rpc->service_name;
537538
struct strbuf buf = STRBUF_INIT;
539+
struct strbuf *preamble = rpc->stdin_preamble;
538540
struct child_process client;
539541
int err = 0;
540542

@@ -545,6 +547,8 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
545547
client.argv = rpc->argv;
546548
if (start_command(&client))
547549
exit(1);
550+
if (preamble)
551+
write_or_die(client.in, preamble->buf, preamble->len);
548552
if (heads)
549553
write_or_die(client.in, heads->buf, heads->len);
550554

@@ -626,13 +630,14 @@ static int fetch_git(struct discovery *heads,
626630
int nr_heads, struct ref **to_fetch)
627631
{
628632
struct rpc_state rpc;
633+
struct strbuf preamble = STRBUF_INIT;
629634
char *depth_arg = NULL;
630-
const char **argv;
631635
int argc = 0, i, err;
636+
const char *argv[15];
632637

633-
argv = xmalloc((15 + nr_heads) * sizeof(char*));
634638
argv[argc++] = "fetch-pack";
635639
argv[argc++] = "--stateless-rpc";
640+
argv[argc++] = "--stdin";
636641
argv[argc++] = "--lock-pack";
637642
if (options.followtags)
638643
argv[argc++] = "--include-tag";
@@ -651,24 +656,27 @@ static int fetch_git(struct discovery *heads,
651656
argv[argc++] = depth_arg;
652657
}
653658
argv[argc++] = url;
659+
argv[argc++] = NULL;
660+
654661
for (i = 0; i < nr_heads; i++) {
655662
struct ref *ref = to_fetch[i];
656663
if (!ref->name || !*ref->name)
657664
die("cannot fetch by sha1 over smart http");
658-
argv[argc++] = ref->name;
665+
packet_buf_write(&preamble, "%s\n", ref->name);
659666
}
660-
argv[argc++] = NULL;
667+
packet_buf_flush(&preamble);
661668

662669
memset(&rpc, 0, sizeof(rpc));
663670
rpc.service_name = "git-upload-pack",
664671
rpc.argv = argv;
672+
rpc.stdin_preamble = &preamble;
665673
rpc.gzip_request = 1;
666674

667675
err = rpc_service(&rpc, heads);
668676
if (rpc.result.len)
669677
safe_write(1, rpc.result.buf, rpc.result.len);
670678
strbuf_release(&rpc.result);
671-
free(argv);
679+
strbuf_release(&preamble);
672680
free(depth_arg);
673681
return err;
674682
}

0 commit comments

Comments
 (0)