git_connect(): use common return point

Use only one return point from git_connect(), doing the

    free();
    return conn;

only at one place in the code.

There may be a little confusion what the variable "host" is for.  At
some places it is only the host part, at other places it may include
the port number, so change host into hostandport here.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Torsten Bögershausen 2013-11-28 20:50:15 +01:00 committed by Junio C Hamano
parent c59ab2e52a
commit a2036d7e00
1 changed files with 46 additions and 54 deletions

View File

@ -656,7 +656,7 @@ static struct child_process no_fork;
struct child_process *git_connect(int fd[2], const char *url, struct child_process *git_connect(int fd[2], const char *url,
const char *prog, int flags) const char *prog, int flags)
{ {
char *host, *path; char *hostandport, *path;
struct child_process *conn = &no_fork; struct child_process *conn = &no_fork;
enum protocol protocol; enum protocol protocol;
const char **arg; const char **arg;
@ -667,26 +667,22 @@ struct child_process *git_connect(int fd[2], const char *url,
*/ */
signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, SIG_DFL);


protocol = parse_connect_url(url, &host, &path); protocol = parse_connect_url(url, &hostandport, &path);
if (flags & CONNECT_DIAG_URL) { if (flags & CONNECT_DIAG_URL) {
printf("Diag: url=%s\n", url ? url : "NULL"); printf("Diag: url=%s\n", url ? url : "NULL");
printf("Diag: protocol=%s\n", prot_name(protocol)); printf("Diag: protocol=%s\n", prot_name(protocol));
printf("Diag: hostandport=%s\n", host ? host : "NULL"); printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
printf("Diag: path=%s\n", path ? path : "NULL"); printf("Diag: path=%s\n", path ? path : "NULL");
free(host); conn = NULL;
free(path); } else if (protocol == PROTO_GIT) {
return NULL;
}

if (protocol == PROTO_GIT) {
/* These underlying connection commands die() if they /* These underlying connection commands die() if they
* cannot connect. * cannot connect.
*/ */
char *target_host = xstrdup(host); char *target_host = xstrdup(hostandport);
if (git_use_proxy(host)) if (git_use_proxy(hostandport))
conn = git_proxy_connect(fd, host); conn = git_proxy_connect(fd, hostandport);
else else
git_tcp_connect(fd, host, flags); git_tcp_connect(fd, hostandport, flags);
/* /*
* Separate original protocol components prog and path * Separate original protocol components prog and path
* from extended host header with a NUL byte. * from extended host header with a NUL byte.
@ -699,11 +695,7 @@ struct child_process *git_connect(int fd[2], const char *url,
prog, path, 0, prog, path, 0,
target_host, 0); target_host, 0);
free(target_host); free(target_host);
free(host); } else {
free(path);
return conn;
}

conn = xcalloc(1, sizeof(*conn)); conn = xcalloc(1, sizeof(*conn));


strbuf_addstr(&cmd, prog); strbuf_addstr(&cmd, prog);
@ -715,7 +707,7 @@ struct child_process *git_connect(int fd[2], const char *url,
if (protocol == PROTO_SSH) { if (protocol == PROTO_SSH) {
const char *ssh = getenv("GIT_SSH"); const char *ssh = getenv("GIT_SSH");
int putty = ssh && strcasestr(ssh, "plink"); int putty = ssh && strcasestr(ssh, "plink");
char *ssh_host = host; /* keep host for the free() below */ char *ssh_host = hostandport;
const char *port = NULL; const char *port = NULL;
get_host_and_port(&ssh_host, &port); get_host_and_port(&ssh_host, &port);
port = get_port_numeric(port); port = get_port_numeric(port);
@ -731,8 +723,7 @@ struct child_process *git_connect(int fd[2], const char *url,
*arg++ = port; *arg++ = port;
} }
*arg++ = ssh_host; *arg++ = ssh_host;
} } else {
else {
/* remove repo-local variables from the environment */ /* remove repo-local variables from the environment */
conn->env = local_repo_env; conn->env = local_repo_env;
conn->use_shell = 1; conn->use_shell = 1;
@ -746,7 +737,8 @@ struct child_process *git_connect(int fd[2], const char *url,
fd[0] = conn->out; /* read from child's stdout */ fd[0] = conn->out; /* read from child's stdout */
fd[1] = conn->in; /* write to child's stdin */ fd[1] = conn->in; /* write to child's stdin */
strbuf_release(&cmd); strbuf_release(&cmd);
free(host); }
free(hostandport);
free(path); free(path);
return conn; return conn;
} }