transport-helper: refactor process_connect_service
A future patch will need to take advantage of the logic which runs and processes the response of the connect command on a remote helper so factor out this logic from 'process_connect_service()' and place it into a helper function 'run_connect()'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Mar 15, 2018 at 10:31 UTC
176e85c1b4bd055633e01dd7bb717191d369e8a1
1 file changed
+38
-29
transport-helper.c
+38
-29
@@ -545,14 +545,13 @@ static int fetch_with_import(struct transport *transport,
545
return 0;
546
}
547
548
-static int process_connect_service(struct transport *transport,
549
- const char *name, const char *exec)
548
+static int run_connect(struct transport *transport, struct strbuf *cmdbuf)
549
{
550
struct helper_data *data = transport->data;
552
- struct strbuf cmdbuf = STRBUF_INIT;
553
- struct child_process *helper;
554
- int r, duped, ret = 0;
551
+ int ret = 0;
552
+ int duped;
553
FILE *input;
554
+ struct child_process *helper;
555
556
helper = get_helper(transport);
557
@@ -568,44 +567,54 @@ static int process_connect_service(struct transport *transport,
567
input = xfdopen(duped, "r");
568
setvbuf(input, NULL, _IONBF, 0);
569
570
+ sendline(data, cmdbuf);
571
+ if (recvline_fh(input, cmdbuf))
572
+ exit(128);
573
+
574
+ if (!strcmp(cmdbuf->buf, "")) {
575
+ data->no_disconnect_req = 1;
576
+ if (debug)
577
+ fprintf(stderr, "Debug: Smart transport connection "
578
+ "ready.\n");
579
+ ret = 1;
580
+ } else if (!strcmp(cmdbuf->buf, "fallback")) {
581
+ if (debug)
582
+ fprintf(stderr, "Debug: Falling back to dumb "
583
+ "transport.\n");
584
+ } else {
585
+ die("Unknown response to connect: %s",
586
+ cmdbuf->buf);
587
+ }
588
+
589
+ fclose(input);
590
+ return ret;
591
+}
592
+
593
+static int process_connect_service(struct transport *transport,
594
+ const char *name, const char *exec)
595
+{
596
+ struct helper_data *data = transport->data;
597
+ struct strbuf cmdbuf = STRBUF_INIT;
598
+ int ret = 0;
599
+
600
/*
601
* Handle --upload-pack and friends. This is fire and forget...
602
* just warn if it fails.
603
*/
604
if (strcmp(name, exec)) {
576
- r = set_helper_option(transport, "servpath", exec);
605
+ int r = set_helper_option(transport, "servpath", exec);
606
if (r > 0)
607
warning("Setting remote service path not supported by protocol.");
608
else if (r < 0)
609
warning("Invalid remote service path.");
610
}
611
583
- if (data->connect)
612
+ if (data->connect) {
613
strbuf_addf(&cmdbuf, "connect %s\n", name);
585
- else
586
- goto exit;
587
-
588
- sendline(data, &cmdbuf);
589
- if (recvline_fh(input, &cmdbuf))
590
- exit(128);
591
-
592
- if (!strcmp(cmdbuf.buf, "")) {
593
- data->no_disconnect_req = 1;
594
- if (debug)
595
- fprintf(stderr, "Debug: Smart transport connection "
596
- "ready.\n");
597
- ret = 1;
598
- } else if (!strcmp(cmdbuf.buf, "fallback")) {
599
- if (debug)
600
- fprintf(stderr, "Debug: Falling back to dumb "
601
- "transport.\n");
602
- } else
603
- die("Unknown response to connect: %s",
604
- cmdbuf.buf);
614
+ ret = run_connect(transport, &cmdbuf);
615
+ }
616
606
-exit:
617
strbuf_release(&cmdbuf);
608
- fclose(input);
618
return ret;
619
}
620