git-2.22.0/connect.c
/*
 * Extract protocol and relevant parts from the specified connection URL.
 * The caller must free() the returned strings.
 */
Extract protocol and relevant parts from the specified connection URL.
The caller must free() the returned strings.
Extract protocol and relevant parts from the specified connection URL . The caller must free () the returned strings .
static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
				       char **ret_path)
{
	char *url;
	char *host, *path;
	char *end;
	int separator = '/';
	enum protocol protocol = PROTO_LOCAL;
	if (is_url(url_orig))
		url = url_decode(url_orig);
	else
		url = xstrdup(url_orig);
	host = strstr(url, "://");
	if (host) {
		*host = '\0';
		protocol = get_protocol(url);
		host += 3;
	} else {
		host = url;
		if (!url_is_local_not_ssh(url)) {
			protocol = PROTO_SSH;
			separator = ':';
		}
	}
	end = host_end(&host, 0);
	if (protocol == PROTO_LOCAL)
		path = end;
	else if (protocol == PROTO_FILE && has_dos_drive_prefix(end))
		path = end; 
	else
		path = strchr(end, separator);
	if (!path || !*path)
		die(_("no path specified; see 'git help pull' for valid url syntax"));
	end = path; 
	if (separator == ':')
		path++; 
	if (protocol == PROTO_GIT || protocol == PROTO_SSH) {
		if (path[1] == '~')
			path++;
	}
	path = xstrdup(path);
	*end = '\0';
	*ret_host = xstrdup(host);
	*ret_path = path;
	free(url);
	return protocol;
}
static enum protocol parse_connect_url ( const char * url_orig , char * * ret_host , char * * ret_path ) { char * url ; char * host , * path ; char * end ; int separator = ' ' ; enum protocol protocol = PROTO_LOCAL ; if ( is_url ( url_orig ) ) url = url_decode ( url_orig ) ; else url = xstrdup ( url_orig ) ; host = strstr ( url , " " ) ; if ( host ) { * host = ' \0 ' ; protocol = get_protocol ( url ) ; host += 3 ; } else { host = url ; if ( ! url_is_local_not_ssh ( url ) ) { protocol = PROTO_SSH ; separator = ' ' ; } } end = host_end ( & host , 0 ) ; if ( protocol == PROTO_LOCAL ) path = end ; else if ( protocol == PROTO_FILE && has_dos_drive_prefix ( end ) ) path = end ; else path = strchr ( end , separator ) ; if ( ! path || ! * path ) die ( _ ( " " ) ) ; end = path ; if ( separator == ' ' ) path ++ ; if ( protocol == PROTO_GIT || protocol == PROTO_SSH ) { if ( path [ 1 ] == ' ' ) path ++ ; } path = xstrdup ( path ) ; * end = ' \0 ' ; * ret_host = xstrdup ( host ) ; * ret_path = path ; free ( url ) ; return protocol ; }
Extract protocol and relevant parts from the specified connection URL.
Extract protocol and relevant parts from the specified connection URL .
/*
	 * Don't do destructive transforms as protocol code does
	 * '[]' unwrapping in get_host_and_port()
	 */ /* "file://$(pwd)" may be "file://C:/projects/repo" */ /*
	 * null-terminate hostname and point path to ~ for URL's like this:
	 *    ssh://host.xz/~user/repo
	 */ /* Need to \0 terminate host here */ /* path starts after ':' */