@ -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
* Open a connection using Git's native 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
* The caller is responsible for freeing hostandport, but this function may
* will hopefully be changed in a libification effort, to return NULL when
* modify it (for example, to truncate it to remove the port part).
* the connection failed).
*/
*/
struct child_process *git_connect(int fd[2], const char *url,
static struct child_process *git_connect_git(int fd[2], char *hostandport,
const char *prog, int flags)
const char *path, const char *prog,
int flags)
{
{
char *hostandport, *path;
struct child_process *conn;
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;
struct strbuf request = STRBUF_INIT;
/*
/*
* Set up virtual host information based on where we will
* 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);
free(target_host);
strbuf_release(&request);
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 {
} else {
struct strbuf cmd = STRBUF_INIT;
struct strbuf cmd = STRBUF_INIT;
const char *const *var;
const char *const *var;