]> git.ipfire.org Git - thirdparty/git.git/commitdiff
connect: rename enum protocol to url_scheme
authorMatheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Sat, 2 May 2026 05:28:35 +0000 (05:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 May 2026 00:48:26 +0000 (09:48 +0900)
RFC 1738 names the part of a URL before the colon a "scheme".
connect.c calls it "protocol", which is more generic
and collides with the unrelated enum protocol_version.

Rename:

    enum protocol -> enum url_scheme
    PROTO_*       -> URL_SCHEME_*
    prot_name     -> url_scheme_name
    get_protocol  -> url_get_scheme

The local variables in parse_connect_url and git_connect
are renamed accordingly, from protocol to scheme.

No behavior change. The user-visible diagnostics
and translated error messages are preserved:

    "Diag: protocol=..."
    "protocol '%s' is not supported"
    "unknown protocol"

This rename also prepares for moving the scheme-detection functions
to a shared header so that a future plumbing command can parse URLs
using the same logic as the connect path.

Suggested-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
connect.c

index fcd35c5539a76e4f694f8392615de262c5b40c6d..46da89905ee7c655656a7b5a64a20a3d4449cb73 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -700,11 +700,11 @@ int server_supports(const char *feature)
        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)
@@ -715,33 +715,33 @@ 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);
 }
 
@@ -1083,14 +1083,14 @@ static char *get_port(char *host)
  * 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);
@@ -1100,12 +1100,12 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
        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 = ':';
                }
        }
@@ -1116,13 +1116,13 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
         */
        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);
@@ -1138,7 +1138,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
        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++;
        }
@@ -1149,7 +1149,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
        *ret_host = xstrdup(host);
        *ret_path = path;
        free(url);
-       return protocol;
+       return scheme;
 }
 
 static const char *get_ssh_command(void)
@@ -1434,7 +1434,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 {
        char *hostandport, *path;
        struct child_process *conn;
-       enum protocol protocol;
+       enum url_scheme scheme;
        enum protocol_version version = get_protocol_version_config();
 
        /*
@@ -1451,14 +1451,14 @@ struct child_process *git_connect(int fd[2], const char *url,
         */
        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 {
@@ -1481,7 +1481,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 
                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");
@@ -1492,7 +1492,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 
                        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");