url: move scheme detection to URL header/source
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>
Matheus Afonso Martins Moreira committed
May 2, 2026 at 05:28 UTC
d48e36a8a23d931e869fbb3156fc95a5732cb061
3 files changed
+29
-22
connect.c
-22
index cb145de30e..1ac7acc6e8 100644
--- 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;
url.c
+16
index 057576042a..300acf98fe 100644
--- 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);
+}
url.h
+13
index 39d621312f..24c8cd91d0 100644
--- 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