700
return !!server_feature_value(feature, NULL);
701
}
702
703
-enum protocol {
704
- PROTO_LOCAL = 1,
705
- PROTO_FILE,
706
- PROTO_SSH,
707
- PROTO_GIT
703
+enum url_scheme {
704
+ URL_SCHEME_LOCAL = 1,
705
+ URL_SCHEME_FILE,
706
+ URL_SCHEME_SSH,
707
+ URL_SCHEME_GIT
708
};
709
710
int url_is_local_not_ssh(const char *url)
715
(has_dos_drive_prefix(url) && is_valid_path(url));
716
}
717
718
-static const char *prot_name(enum protocol protocol)
718
+static const char *url_scheme_name(enum url_scheme scheme)
719
{
720
- switch (protocol) {
721
- case PROTO_LOCAL:
722
- case PROTO_FILE:
720
+ switch (scheme) {
721
+ case URL_SCHEME_LOCAL:
722
+ case URL_SCHEME_FILE:
723
return "file";
724
- case PROTO_SSH:
724
+ case URL_SCHEME_SSH:
725
return "ssh";
726
- case PROTO_GIT:
726
+ case URL_SCHEME_GIT:
727
return "git";
728
default:
729
return "unknown protocol";
730
}
731
}
732
733
-static enum protocol get_protocol(const char *name)
733
+static enum url_scheme url_get_scheme(const char *name)
734
{
735
if (!strcmp(name, "ssh"))
736
- return PROTO_SSH;
736
+ return URL_SCHEME_SSH;
737
if (!strcmp(name, "git"))
738
- return PROTO_GIT;
738
+ return URL_SCHEME_GIT;
739
if (!strcmp(name, "git+ssh")) /* deprecated - do not use */
740
- return PROTO_SSH;
740
+ return URL_SCHEME_SSH;
741
if (!strcmp(name, "ssh+git")) /* deprecated - do not use */
742
- return PROTO_SSH;
742
+ return URL_SCHEME_SSH;
743
if (!strcmp(name, "file"))
744
- return PROTO_FILE;
744
+ return URL_SCHEME_FILE;
745
die(_("protocol '%s' is not supported"), name);
746
}
747
1083
* Extract protocol and relevant parts from the specified connection URL.
1084
* The caller must free() the returned strings.
1085
*/
1086
-static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
1087
- char **ret_path)
1086
+static enum url_scheme parse_connect_url(const char *url_orig, char **ret_host,
1087
+ char **ret_path)
1088
{
1089
char *url;
1090
char *host, *path;
1091
char *end;
1092
int separator = '/';
1093
- enum protocol protocol = PROTO_LOCAL;
1093
+ enum url_scheme scheme = URL_SCHEME_LOCAL;
1094
1095
if (is_url(url_orig))
1096
url = url_decode(url_orig);
1100
host = strstr(url, "://");
1101
if (host) {
1102
*host = '\0';
1103
- protocol = get_protocol(url);
1103
+ scheme = url_get_scheme(url);
1104
host += 3;
1105
} else {
1106
host = url;
1107
if (!url_is_local_not_ssh(url)) {
1108
- protocol = PROTO_SSH;
1108
+ scheme = URL_SCHEME_SSH;
1109
separator = ':';
1110
}
1111
}
1116
*/
1117
end = host_end(&host, 0);
1118
1119
- if (protocol == PROTO_LOCAL)
1119
+ if (scheme == URL_SCHEME_LOCAL)
1120
path = end;
1121
- else if (protocol == PROTO_FILE && *host != '/' &&
1121
+ else if (scheme == URL_SCHEME_FILE && *host != '/' &&
1122
!has_dos_drive_prefix(host) &&
1123
offset_1st_component(host - 2) > 1)
1124
path = host - 2; /* include the leading "//" */
1125
- else if (protocol == PROTO_FILE && has_dos_drive_prefix(end))
1125
+ else if (scheme == URL_SCHEME_FILE && has_dos_drive_prefix(end))
1126
path = end; /* "file://$(pwd)" may be "file://C:/projects/repo" */
1127
else
1128
path = strchr(end, separator);
1138
end = path; /* Need to \0 terminate host here */
1139
if (separator == ':')
1140
path++; /* path starts after ':' */
1141
- if (protocol == PROTO_GIT || protocol == PROTO_SSH) {
1141
+ if (scheme == URL_SCHEME_GIT || scheme == URL_SCHEME_SSH) {
1142
if (path[1] == '~')
1143
path++;
1144
}
1149
*ret_host = xstrdup(host);
1150
*ret_path = path;
1151
free(url);
1152
- return protocol;
1152
+ return scheme;
1153
}
1154
1155
static const char *get_ssh_command(void)
1434
{
1435
char *hostandport, *path;
1436
struct child_process *conn;
1437
- enum protocol protocol;
1437
+ enum url_scheme scheme;
1438
enum protocol_version version = get_protocol_version_config();
1439
1440
/*
1451
*/
1452
signal(SIGCHLD, SIG_DFL);
1453
1454
- protocol = parse_connect_url(url, &hostandport, &path);
1455
- if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
1454
+ scheme = parse_connect_url(url, &hostandport, &path);
1455
+ if ((flags & CONNECT_DIAG_URL) && (scheme != URL_SCHEME_SSH)) {
1456
printf("Diag: url=%s\n", url ? url : "NULL");
1457
- printf("Diag: protocol=%s\n", prot_name(protocol));
1457
+ printf("Diag: protocol=%s\n", url_scheme_name(scheme));
1458
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
1459
printf("Diag: path=%s\n", path ? path : "NULL");
1460
conn = NULL;
1461
- } else if (protocol == PROTO_GIT) {
1461
+ } else if (scheme == URL_SCHEME_GIT) {
1462
conn = git_connect_git(fd, hostandport, path, prog, version, flags);
1463
conn->trace2_child_class = "transport/git";
1464
} else {
1481
1482
conn->use_shell = 1;
1483
conn->in = conn->out = -1;
1484
- if (protocol == PROTO_SSH) {
1484
+ if (scheme == URL_SCHEME_SSH) {
1485
char *ssh_host = hostandport;
1486
const char *port = NULL;
1487
transport_check_allowed("ssh");
1492
1493
if (flags & CONNECT_DIAG_URL) {
1494
printf("Diag: url=%s\n", url ? url : "NULL");
1495
- printf("Diag: protocol=%s\n", prot_name(protocol));
1495
+ printf("Diag: protocol=%s\n", url_scheme_name(scheme));
1496
printf("Diag: userandhost=%s\n", ssh_host ? ssh_host : "NULL");
1497
printf("Diag: port=%s\n", port ? port : "NONE");
1498
printf("Diag: path=%s\n", path ? path : "NULL");