return !!server_feature_value(feature, NULL);
}
-enum protocol {
- PROTO_LOCAL = 1,
- PROTO_FILE,
- PROTO_SSH,
- PROTO_GIT
+enum url_scheme {
+ URL_SCHEME_LOCAL = 1,
+ URL_SCHEME_FILE,
+ URL_SCHEME_SSH,
+ URL_SCHEME_GIT
};
int url_is_local_not_ssh(const char *url)
(has_dos_drive_prefix(url) && is_valid_path(url));
}
-static const char *prot_name(enum protocol protocol)
+static const char *url_scheme_name(enum url_scheme scheme)
{
- switch (protocol) {
- case PROTO_LOCAL:
- case PROTO_FILE:
+ switch (scheme) {
+ case URL_SCHEME_LOCAL:
+ case URL_SCHEME_FILE:
return "file";
- case PROTO_SSH:
+ case URL_SCHEME_SSH:
return "ssh";
- case PROTO_GIT:
+ case URL_SCHEME_GIT:
return "git";
default:
return "unknown protocol";
}
}
-static enum protocol get_protocol(const char *name)
+static enum url_scheme url_get_scheme(const char *name)
{
if (!strcmp(name, "ssh"))
- return PROTO_SSH;
+ return URL_SCHEME_SSH;
if (!strcmp(name, "git"))
- return PROTO_GIT;
+ return URL_SCHEME_GIT;
if (!strcmp(name, "git+ssh")) /* deprecated - do not use */
- return PROTO_SSH;
+ return URL_SCHEME_SSH;
if (!strcmp(name, "ssh+git")) /* deprecated - do not use */
- return PROTO_SSH;
+ return URL_SCHEME_SSH;
if (!strcmp(name, "file"))
- return PROTO_FILE;
+ return URL_SCHEME_FILE;
die(_("protocol '%s' is not supported"), name);
}
* 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)
+static enum url_scheme 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;
+ enum url_scheme scheme = URL_SCHEME_LOCAL;
if (is_url(url_orig))
url = url_decode(url_orig);
host = strstr(url, "://");
if (host) {
*host = '\0';
- protocol = get_protocol(url);
+ scheme = url_get_scheme(url);
host += 3;
} else {
host = url;
if (!url_is_local_not_ssh(url)) {
- protocol = PROTO_SSH;
+ scheme = URL_SCHEME_SSH;
separator = ':';
}
}
*/
end = host_end(&host, 0);
- if (protocol == PROTO_LOCAL)
+ if (scheme == URL_SCHEME_LOCAL)
path = end;
- else if (protocol == PROTO_FILE && *host != '/' &&
+ else if (scheme == URL_SCHEME_FILE && *host != '/' &&
!has_dos_drive_prefix(host) &&
offset_1st_component(host - 2) > 1)
path = host - 2; /* include the leading "//" */
- else if (protocol == PROTO_FILE && has_dos_drive_prefix(end))
+ else if (scheme == URL_SCHEME_FILE && has_dos_drive_prefix(end))
path = end; /* "file://$(pwd)" may be "file://C:/projects/repo" */
else
path = strchr(end, separator);
end = path; /* Need to \0 terminate host here */
if (separator == ':')
path++; /* path starts after ':' */
- if (protocol == PROTO_GIT || protocol == PROTO_SSH) {
+ if (scheme == URL_SCHEME_GIT || scheme == URL_SCHEME_SSH) {
if (path[1] == '~')
path++;
}
*ret_host = xstrdup(host);
*ret_path = path;
free(url);
- return protocol;
+ return scheme;
}
static const char *get_ssh_command(void)
{
char *hostandport, *path;
struct child_process *conn;
- enum protocol protocol;
+ enum url_scheme scheme;
enum protocol_version version = get_protocol_version_config();
/*
*/
signal(SIGCHLD, SIG_DFL);
- protocol = parse_connect_url(url, &hostandport, &path);
- if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
+ scheme = parse_connect_url(url, &hostandport, &path);
+ if ((flags & CONNECT_DIAG_URL) && (scheme != URL_SCHEME_SSH)) {
printf("Diag: url=%s\n", url ? url : "NULL");
- printf("Diag: protocol=%s\n", prot_name(protocol));
+ printf("Diag: protocol=%s\n", url_scheme_name(scheme));
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
printf("Diag: path=%s\n", path ? path : "NULL");
conn = NULL;
- } else if (protocol == PROTO_GIT) {
+ } else if (scheme == URL_SCHEME_GIT) {
conn = git_connect_git(fd, hostandport, path, prog, version, flags);
conn->trace2_child_class = "transport/git";
} else {
conn->use_shell = 1;
conn->in = conn->out = -1;
- if (protocol == PROTO_SSH) {
+ if (scheme == URL_SCHEME_SSH) {
char *ssh_host = hostandport;
const char *port = NULL;
transport_check_allowed("ssh");
if (flags & CONNECT_DIAG_URL) {
printf("Diag: url=%s\n", url ? url : "NULL");
- printf("Diag: protocol=%s\n", prot_name(protocol));
+ printf("Diag: protocol=%s\n", url_scheme_name(scheme));
printf("Diag: userandhost=%s\n", ssh_host ? ssh_host : "NULL");
printf("Diag: port=%s\n", port ? port : "NONE");
printf("Diag: path=%s\n", path ? path : "NULL");