git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 3/8] url: move scheme detection to URL header/source

From
Matheus Afonso Martins Moreira via GitGitGadget <gitgitgadget@gmail.com>
Date
May 2, 2026, 05:28 UTC
Message-ID
<e584fb03f3c23fda452b8e53d287f8f835becd48.1777699722.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1715.v3.git.git.1777699722.gitgitgadget@gmail.com>
From: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>

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>
---
 connect.c | 22 ----------------------
 url.c     | 16 ++++++++++++++++
 url.h     | 13 +++++++++++++
 3 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/connect.c b/connect.c
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;
diff --git a/url.c b/url.c
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);
+}
diff --git a/url.h b/url.h
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
-- 
gitgitgadget
Previous: Matheus Afonso Martins Moreira via GitGitGadgetNext: Matheus Afonso Martins Moreira via GitGitGadget
Message 33 of 44 in “builtin: implement, document and test url-parse”
  1. 00/13 builtin: implement, document and test url-parseMatheus Moreira via GitGitGadget, Apr 28, 2024
  2. 01/13 url: move helper function to URL header and sourceMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  3. 02/13 urlmatch: define url_parse functionMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  4. Ghanshyam ThakkarMay 1, 2024
  5. Torsten BögershausenMay 2, 2024
  6. 03/13 builtin: create url-parse commandMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  7. 04/13 url-parse: add URL parsing helper functionMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  8. 05/13 url-parse: enumerate possible URL componentsMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  9. 06/13 url-parse: define component extraction helper fnMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  10. 07/13 url-parse: define string to component converter fnMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  11. 08/13 url-parse: define usage and optionsMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  12. 09/13 url-parse: parse options given on the command lineMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  13. 10/13 url-parse: validate all given git URLsMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  14. 11/13 url-parse: output URL components selected by userMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  15. 12/13 Documentation: describe the url-parse builtinMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  16. Ghanshyam ThakkarApr 30, 2024
  17. 13/13 tests: add tests for the new url-parse builtinMatheus Afonso Martins Moreira via GitGitGadget, Apr 28, 2024
  18. Torsten BögershausenApr 29, 2024
  19. Reply to community feedbackMatheus Afonso Martins Moreira, Apr 29, 2024
  20. Torsten BögershausenApr 30, 2024
  21. 0/8 builtin: implement, document and test url-parseMatheus Moreira via GitGitGadget, May 1, 2026
  22. 1/8 connect: rename enum protocol to url_schemeMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  23. 2/8 url: move url_is_local_not_ssh to url.hMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  24. 3/8 url: move scheme detection to URL header/sourceMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  25. 4/8 url: return URL_SCHEME_UNKNOWN instead of dyingMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  26. 5/8 urlmatch: define url_parse functionMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  27. 6/8 builtin: create url-parse commandMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  28. 7/8 doc: describe the url-parse builtinMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  29. 8/8 t9904: add tests for the new url-parse builtinMatheus Afonso Martins Moreira via GitGitGadget, May 1, 2026
  30. 0/8 builtin: implement, document and test url-parseMatheus Moreira via GitGitGadget, May 2, 2026
  31. 1/8 connect: rename enum protocol to url_schemeMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  32. 2/8 url: move url_is_local_not_ssh to url.hMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  33. 3/8 url: move scheme detection to URL header/sourceMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  34. 4/8 url: return URL_SCHEME_UNKNOWN instead of dyingMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  35. 5/8 urlmatch: define url_parse functionMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  36. 6/8 builtin: create url-parse commandMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  37. 7/8 doc: describe the url-parse builtinMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  38. 8/8 t9904: add tests for the new url-parse builtinMatheus Afonso Martins Moreira via GitGitGadget, May 2, 2026
  39. Junio C HamanoMay 3, 2026
  40. Matheus Afonso Martins MoreiraMay 3, 2026
  41. Torsten BögershausenMay 3, 2026
  42. Matheus Afonso Martins MoreiraMay 3, 2026
  43. Junio C HamanoMay 12, 2026
  44. Torsten BögershausenMay 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.