Skip to content

Commit 176e85c

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b1c2edf commit 176e85c

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

transport-helper.c

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,13 @@ static int fetch_with_import(struct transport *transport,
545545
return 0;
546546
}
547547

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)
550549
{
551550
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;
555553
FILE *input;
554+
struct child_process *helper;
556555

557556
helper = get_helper(transport);
558557

@@ -568,44 +567,54 @@ static int process_connect_service(struct transport *transport,
568567
input = xfdopen(duped, "r");
569568
setvbuf(input, NULL, _IONBF, 0);
570569

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+
571600
/*
572601
* Handle --upload-pack and friends. This is fire and forget...
573602
* just warn if it fails.
574603
*/
575604
if (strcmp(name, exec)) {
576-
r = set_helper_option(transport, "servpath", exec);
605+
int r = set_helper_option(transport, "servpath", exec);
577606
if (r > 0)
578607
warning("Setting remote service path not supported by protocol.");
579608
else if (r < 0)
580609
warning("Invalid remote service path.");
581610
}
582611

583-
if (data->connect)
612+
if (data->connect) {
584613
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+
}
605616

606-
exit:
607617
strbuf_release(&cmdbuf);
608-
fclose(input);
609618
return ret;
610619
}
611620

0 commit comments

Comments
 (0)