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
@@ -700,13 +700,6 @@ int server_supports(const char *feature)
700
return !!server_feature_value(feature, NULL);
701
}
702
703
-enum url_scheme {
704
- URL_SCHEME_LOCAL = 1,
705
- URL_SCHEME_FILE,
706
- URL_SCHEME_SSH,
707
- URL_SCHEME_GIT
708
-};
709
-
703
static const char *url_scheme_name(enum url_scheme scheme)
704
{
705
switch (scheme) {
@@ -722,21 +715,6 @@ static const char *url_scheme_name(enum url_scheme scheme)
715
}
716
}
717
725
-static enum url_scheme url_get_scheme(const char *name)
726
-{
727
- if (!strcmp(name, "ssh"))
728
- return URL_SCHEME_SSH;
729
- if (!strcmp(name, "git"))
730
- return URL_SCHEME_GIT;
731
- if (!strcmp(name, "git+ssh")) /* deprecated - do not use */
732
- return URL_SCHEME_SSH;
733
- if (!strcmp(name, "ssh+git")) /* deprecated - do not use */
734
- return URL_SCHEME_SSH;
735
- if (!strcmp(name, "file"))
736
- return URL_SCHEME_FILE;
737
- die(_("protocol '%s' is not supported"), name);
738
-}
739
-
718
static char *host_end(char **hoststart, int removebrackets)
719
{
720
char *host = *hoststart;
url.c
+16
@@ -1,4 +1,5 @@
1
#include "git-compat-util.h"
2
+#include "gettext.h"
3
#include "hex-ll.h"
4
#include "strbuf.h"
5
#include "url.h"
@@ -140,3 +141,18 @@ int url_is_local_not_ssh(const char *url)
141
return !colon || (slash && slash < colon) ||
142
(has_dos_drive_prefix(url) && is_valid_path(url));
143
}
144
+
145
+enum url_scheme url_get_scheme(const char *name)
146
+{
147
+ if (!strcmp(name, "ssh"))
148
+ return URL_SCHEME_SSH;
149
+ if (!strcmp(name, "git"))
150
+ return URL_SCHEME_GIT;
151
+ if (!strcmp(name, "git+ssh")) /* deprecated - do not use */
152
+ return URL_SCHEME_SSH;
153
+ if (!strcmp(name, "ssh+git")) /* deprecated - do not use */
154
+ return URL_SCHEME_SSH;
155
+ if (!strcmp(name, "file"))
156
+ return URL_SCHEME_FILE;
157
+ die(_("protocol '%s' is not supported"), name);
158
+}
url.h
+13
@@ -23,6 +23,19 @@ void str_end_url_with_slash(const char *url, char **dest);
23
24
int url_is_local_not_ssh(const char *url);
25
26
+enum url_scheme {
27
+ URL_SCHEME_LOCAL = 1,
28
+ URL_SCHEME_FILE,
29
+ URL_SCHEME_SSH,
30
+ URL_SCHEME_GIT,
31
+};
32
+
33
+/*
34
+ * Identify the URL scheme by name. Dies if the name does not match
35
+ * any scheme that Git knows about.
36
+ */
37
+enum url_scheme url_get_scheme(const char *name);
38
+
39
/*
40
* The set of unreserved characters as per STD66 (RFC3986) is
41
* '[A-Za-z0-9-._~]'. These characters are safe to appear in URI