url: return URL_SCHEME_UNKNOWN instead of dying

Enumerate a URL_SCHEME_UNKNOWN result with value 0. Have url_get_scheme() return it for unrecognized schemes instead of calling die() itself. Move the die() call to parse_connect_url() where url_get_scheme() is used. This lets url_get_scheme() be used from contexts that need to identify a URL's scheme without aborting the program. For example, a future plumbing command that validates URLs. No external behavior change. parse_connect_url() still dies with the same translated message for unrecognized schemes. 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 46d6fb752e7d8550a3511eb370536d216ddb5b8f
3 files changed +7 -5
connect.c
+2
@@ -1071,6 +1071,8 @@ static enum url_scheme parse_connect_url(const char *url_orig, char **ret_host,
1071 if (host) {
1072 *host = '\0';
1073 scheme = url_get_scheme(url);
1074 + if (scheme == URL_SCHEME_UNKNOWN)
1075 + die(_("protocol '%s' is not supported"), url);
1076 host += 3;
1077 } else {
1078 host = url;
url.c
+1 -2
@@ -1,5 +1,4 @@
1 #include "git-compat-util.h"
2 -#include "gettext.h"
2 #include "hex-ll.h"
3 #include "strbuf.h"
4 #include "url.h"
@@ -154,5 +153,5 @@ enum url_scheme url_get_scheme(const char *name)
153 return URL_SCHEME_SSH;
154 if (!strcmp(name, "file"))
155 return URL_SCHEME_FILE;
157 - die(_("protocol '%s' is not supported"), name);
156 + return URL_SCHEME_UNKNOWN;
157 }
url.h
+4 -3
@@ -24,15 +24,16 @@ void str_end_url_with_slash(const char *url, char **dest);
24 int url_is_local_not_ssh(const char *url);
25
26 enum url_scheme {
27 - URL_SCHEME_LOCAL = 1,
27 + URL_SCHEME_UNKNOWN = 0,
28 + URL_SCHEME_LOCAL,
29 URL_SCHEME_FILE,
30 URL_SCHEME_SSH,
31 URL_SCHEME_GIT,
32 };
33
34 /*
34 - * Identify the URL scheme by name. Dies if the name does not match
35 - * any scheme that Git knows about.
35 + * Identify the URL scheme by name. Returns URL_SCHEME_UNKNOWN
36 + * if the name does not match any scheme that Git knows about.
37 */
38 enum url_scheme url_get_scheme(const char *name);
39