]> git.ipfire.org Git - thirdparty/git.git/commitdiff
url: move scheme detection to URL header/source
authorMatheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Sat, 2 May 2026 05:28:37 +0000 (05:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 May 2026 00:48:27 +0000 (09:48 +0900)
Move enum url_scheme and url_get_scheme()
from connect.c to url.h and url.c
so that other code can identify
a URL's scheme without depending
on connect.c.

No behavior change. url_get_scheme() still dies
on an unrecognized scheme name, with the same
translated message as before.

scheme_name() stays in connect.c
because it has no other callers.

Signed-off-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
connect.c
url.c
url.h

index cb145de30e502cf8f1aabfbfe4ca77225c5652ca..1ac7acc6e881db8a343db78e803b575e2a6f1dc5 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -700,13 +700,6 @@ int server_supports(const char *feature)
        return !!server_feature_value(feature, NULL);
 }
 
-enum url_scheme {
-       URL_SCHEME_LOCAL = 1,
-       URL_SCHEME_FILE,
-       URL_SCHEME_SSH,
-       URL_SCHEME_GIT
-};
-
 static const char *url_scheme_name(enum url_scheme scheme)
 {
        switch (scheme) {
@@ -722,21 +715,6 @@ static const char *url_scheme_name(enum url_scheme scheme)
        }
 }
 
-static enum url_scheme url_get_scheme(const char *name)
-{
-       if (!strcmp(name, "ssh"))
-               return URL_SCHEME_SSH;
-       if (!strcmp(name, "git"))
-               return URL_SCHEME_GIT;
-       if (!strcmp(name, "git+ssh")) /* deprecated - do not use */
-               return URL_SCHEME_SSH;
-       if (!strcmp(name, "ssh+git")) /* deprecated - do not use */
-               return URL_SCHEME_SSH;
-       if (!strcmp(name, "file"))
-               return URL_SCHEME_FILE;
-       die(_("protocol '%s' is not supported"), name);
-}
-
 static char *host_end(char **hoststart, int removebrackets)
 {
        char *host = *hoststart;
diff --git a/url.c b/url.c
index 057576042af1be4d6ee340f956a8d4357689c8f2..300acf98feae03e8566d5609ffb42e7b658073c2 100644 (file)
--- a/url.c
+++ b/url.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "gettext.h"
 #include "hex-ll.h"
 #include "strbuf.h"
 #include "url.h"
@@ -140,3 +141,18 @@ int url_is_local_not_ssh(const char *url)
        return !colon || (slash && slash < colon) ||
                (has_dos_drive_prefix(url) && is_valid_path(url));
 }
+
+enum url_scheme url_get_scheme(const char *name)
+{
+       if (!strcmp(name, "ssh"))
+               return URL_SCHEME_SSH;
+       if (!strcmp(name, "git"))
+               return URL_SCHEME_GIT;
+       if (!strcmp(name, "git+ssh")) /* deprecated - do not use */
+               return URL_SCHEME_SSH;
+       if (!strcmp(name, "ssh+git")) /* deprecated - do not use */
+               return URL_SCHEME_SSH;
+       if (!strcmp(name, "file"))
+               return URL_SCHEME_FILE;
+       die(_("protocol '%s' is not supported"), name);
+}
diff --git a/url.h b/url.h
index 39d621312ffdcb554ded01c429b965e9e5d1d99c..24c8cd91d0f02e9eab40c343548fdd9eb9ebce87 100644 (file)
--- a/url.h
+++ b/url.h
@@ -23,6 +23,19 @@ void str_end_url_with_slash(const char *url, char **dest);
 
 int url_is_local_not_ssh(const char *url);
 
+enum url_scheme {
+       URL_SCHEME_LOCAL = 1,
+       URL_SCHEME_FILE,
+       URL_SCHEME_SSH,
+       URL_SCHEME_GIT,
+};
+
+/*
+ * Identify the URL scheme by name. Dies if the name does not match
+ * any scheme that Git knows about.
+ */
+enum url_scheme url_get_scheme(const char *name);
+
 /*
  * The set of unreserved characters as per STD66 (RFC3986) is
  * '[A-Za-z0-9-._~]'. These characters are safe to appear in URI