]> git.ipfire.org Git - thirdparty/git.git/commitdiff
url: return URL_SCHEME_UNKNOWN instead of dying
authorMatheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Sat, 2 May 2026 05:28:38 +0000 (05:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 May 2026 00:48:27 +0000 (09:48 +0900)
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>
connect.c
url.c
url.h

index 1ac7acc6e881db8a343db78e803b575e2a6f1dc5..73d7a6b8d03afed670296a14a37240780ce3c4ce 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -1071,6 +1071,8 @@ static enum url_scheme parse_connect_url(const char *url_orig, char **ret_host,
        if (host) {
                *host = '\0';
                scheme = url_get_scheme(url);
+               if (scheme == URL_SCHEME_UNKNOWN)
+                       die(_("protocol '%s' is not supported"), url);
                host += 3;
        } else {
                host = url;
diff --git a/url.c b/url.c
index 300acf98feae03e8566d5609ffb42e7b658073c2..a59818278f49df297935cf13d51d39bce9bc2f14 100644 (file)
--- a/url.c
+++ b/url.c
@@ -1,5 +1,4 @@
 #include "git-compat-util.h"
-#include "gettext.h"
 #include "hex-ll.h"
 #include "strbuf.h"
 #include "url.h"
@@ -154,5 +153,5 @@ enum url_scheme url_get_scheme(const char *name)
                return URL_SCHEME_SSH;
        if (!strcmp(name, "file"))
                return URL_SCHEME_FILE;
-       die(_("protocol '%s' is not supported"), name);
+       return URL_SCHEME_UNKNOWN;
 }
diff --git a/url.h b/url.h
index 24c8cd91d0f02e9eab40c343548fdd9eb9ebce87..728952360586a9eea885e491aae0ecf6a2fe3944 100644 (file)
--- a/url.h
+++ b/url.h
@@ -24,15 +24,16 @@ 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_UNKNOWN = 0,
+       URL_SCHEME_LOCAL,
        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.
+ * Identify the URL scheme by name. Returns URL_SCHEME_UNKNOWN
+ * if the name does not match any scheme that Git knows about.
  */
 enum url_scheme url_get_scheme(const char *name);