connect: split git:// setup into a separate function
The git_connect function is growing long. Split the PROTO_GIT-specific portion to a separate function to make it easier to read. No functional change intended. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
8e349780ec
commit
2ac67cb63b
67
connect.c
67
connect.c
|
@ -862,36 +862,16 @@ static enum ssh_variant determine_ssh_variant(const char *ssh_command,
|
|||
}
|
||||
|
||||
/*
|
||||
* This returns the dummy child_process `no_fork` if the transport protocol
|
||||
* does not need fork(2), or a struct child_process object if it does. Once
|
||||
* done, finish the connection with finish_connect() with the value returned
|
||||
* from this function (it is safe to call finish_connect() with NULL to
|
||||
* support the former case).
|
||||
* Open a connection using Git's native protocol.
|
||||
*
|
||||
* If it returns, the connect is successful; it just dies on errors (this
|
||||
* will hopefully be changed in a libification effort, to return NULL when
|
||||
* the connection failed).
|
||||
* The caller is responsible for freeing hostandport, but this function may
|
||||
* modify it (for example, to truncate it to remove the port part).
|
||||
*/
|
||||
struct child_process *git_connect(int fd[2], const char *url,
|
||||
const char *prog, int flags)
|
||||
static struct child_process *git_connect_git(int fd[2], char *hostandport,
|
||||
const char *path, const char *prog,
|
||||
int flags)
|
||||
{
|
||||
char *hostandport, *path;
|
||||
struct child_process *conn;
|
||||
enum protocol protocol;
|
||||
|
||||
/* Without this we cannot rely on waitpid() to tell
|
||||
* what happened to our children.
|
||||
*/
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
|
||||
protocol = parse_connect_url(url, &hostandport, &path);
|
||||
if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
|
||||
printf("Diag: url=%s\n", url ? url : "NULL");
|
||||
printf("Diag: protocol=%s\n", prot_name(protocol));
|
||||
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
|
||||
printf("Diag: path=%s\n", path ? path : "NULL");
|
||||
conn = NULL;
|
||||
} else if (protocol == PROTO_GIT) {
|
||||
struct strbuf request = STRBUF_INIT;
|
||||
/*
|
||||
* Set up virtual host information based on where we will
|
||||
|
@ -936,6 +916,41 @@ struct child_process *git_connect(int fd[2], const char *url,
|
|||
|
||||
free(target_host);
|
||||
strbuf_release(&request);
|
||||
return conn;
|
||||
}
|
||||
|
||||
/*
|
||||
* This returns the dummy child_process `no_fork` if the transport protocol
|
||||
* does not need fork(2), or a struct child_process object if it does. Once
|
||||
* done, finish the connection with finish_connect() with the value returned
|
||||
* from this function (it is safe to call finish_connect() with NULL to
|
||||
* support the former case).
|
||||
*
|
||||
* If it returns, the connect is successful; it just dies on errors (this
|
||||
* will hopefully be changed in a libification effort, to return NULL when
|
||||
* the connection failed).
|
||||
*/
|
||||
struct child_process *git_connect(int fd[2], const char *url,
|
||||
const char *prog, int flags)
|
||||
{
|
||||
char *hostandport, *path;
|
||||
struct child_process *conn;
|
||||
enum protocol protocol;
|
||||
|
||||
/* Without this we cannot rely on waitpid() to tell
|
||||
* what happened to our children.
|
||||
*/
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
|
||||
protocol = parse_connect_url(url, &hostandport, &path);
|
||||
if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
|
||||
printf("Diag: url=%s\n", url ? url : "NULL");
|
||||
printf("Diag: protocol=%s\n", prot_name(protocol));
|
||||
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
|
||||
printf("Diag: path=%s\n", path ? path : "NULL");
|
||||
conn = NULL;
|
||||
} else if (protocol == PROTO_GIT) {
|
||||
conn = git_connect_git(fd, hostandport, path, prog, flags);
|
||||
} else {
|
||||
struct strbuf cmd = STRBUF_INIT;
|
||||
const char *const *var;
|
||||
|
|
Loading…
Reference in New Issue