git-2.22.0/connect.c
/*
 * Open a connection using Git's native protocol.
 *
 * The caller is responsible for freeing hostandport, but this function may
 * modify it (for example, to truncate it to remove the port part).
 */
Open a connection using Git's native protocol.
The caller is responsible for freeing hostandport, but this function may
modify it (for example, to truncate it to remove the port part).
Open a connection using Git ' s native protocol . The caller is responsible for freeing hostandport but this function may modify it ( for example to truncate it to remove the port part ) .
static struct child_process *git_connect_git(int fd[2], char *hostandport,
					     const char *path, const char *prog,
					     enum protocol_version version,
					     int flags)
{
	struct child_process *conn;
	struct strbuf request = STRBUF_INIT;
	char *target_host = getenv("GIT_OVERRIDE_VIRTUAL_HOST");
	if (target_host)
		target_host = xstrdup(target_host);
	else
		target_host = xstrdup(hostandport);
	transport_check_allowed("git");
	if (git_use_proxy(hostandport))
		conn = git_proxy_connect(fd, hostandport);
	else
		conn = git_tcp_connect(fd, hostandport, flags);
	strbuf_addf(&request,
		    "%s %s%chost=%s%c",
		    prog, path, 0,
		    target_host, 0);
	if (version > 0) {
		strbuf_addch(&request, '\0');
		strbuf_addf(&request, "version=%d%c",
			    version, '\0');
	}
	packet_write(fd[1], request.buf, request.len);
	free(target_host);
	strbuf_release(&request);
	return conn;
}
static struct child_process * git_connect_git ( int fd [ 2 ] , char * hostandport , const char * path , const char * prog , enum protocol_version version , int flags ) { struct child_process * conn ; struct strbuf request = STRBUF_INIT ; char * target_host = getenv ( " " ) ; if ( target_host ) target_host = xstrdup ( target_host ) ; else target_host = xstrdup ( hostandport ) ; transport_check_allowed ( " " ) ; if ( git_use_proxy ( hostandport ) ) conn = git_proxy_connect ( fd , hostandport ) ; else conn = git_tcp_connect ( fd , hostandport , flags ) ; strbuf_addf ( & request , " " , prog , path , 0 , target_host , 0 ) ; if ( version > 0 ) { strbuf_addch ( & request , ' \0 ' ) ; strbuf_addf ( & request , " " , version , ' \0 ' ) ; } packet_write ( fd [ 1 ] , request . buf , request . len ) ; free ( target_host ) ; strbuf_release ( & request ) ; return conn ; }
Open a connection using Git's native protocol.
Open a connection using Git ' s native protocol .
/*
	 * Set up virtual host information based on where we will
	 * connect, unless the user has overridden us in
	 * the environment.
	 */ /*
	 * These underlying connection commands die() if they
	 * cannot connect.
	 */ /*
	 * Separate original protocol components prog and path
	 * from extended host header with a NUL byte.
	 *
	 * Note: Do not add any other headers here!  Doing so
	 * will cause older git-daemon servers to crash.
	 */ /* If using a new version put that stuff here after a second null byte */