]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/credential-store: move is_rfc3986_unreserved to url.[ch]
authorAdrian Ratiu <adrian.ratiu@collabora.com>
Sat, 20 Dec 2025 10:15:24 +0000 (12:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 21 Dec 2025 02:36:01 +0000 (11:36 +0900)
is_rfc3986_unreserved() was moved to credential-store.c and was made
static by f89854362c (credential-store: move related functions to
credential-store file, 2023-06-06) under a correct assumption, at the
time, that it was the only place using it.

However now we need it to apply URL-encoding to submodule names when
constructing gitdir paths, to avoid conflicts, so bring it back as a
public function exposed via url.h, instead of the old helper path
(strbuf), which has nothing to do with 3986 encoding/decoding anymore.

This function will be used in subsequent commits which do the encoding.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/credential-store.c
url.c
url.h

index b74e06cc93d9cda13550a3bf2a161ea9775756af..bc1453c6b2b1b2f5ea4f5b9278589a62ac6f999d 100644 (file)
@@ -7,6 +7,7 @@
 #include "path.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "url.h"
 #include "write-or-die.h"
 
 static struct lock_file credential_lock;
@@ -76,12 +77,6 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
                die_errno("unable to write credential store");
 }
 
-static int is_rfc3986_unreserved(char ch)
-{
-       return isalnum(ch) ||
-               ch == '-' || ch == '_' || ch == '.' || ch == '~';
-}
-
 static int is_rfc3986_reserved_or_unreserved(char ch)
 {
        if (is_rfc3986_unreserved(ch))
diff --git a/url.c b/url.c
index 282b12495ae7d4af9db51a76017af6065b924d3a..adc289229c6491b4cba42b7d94c16884b8cdee49 100644 (file)
--- a/url.c
+++ b/url.c
@@ -3,6 +3,12 @@
 #include "strbuf.h"
 #include "url.h"
 
+int is_rfc3986_unreserved(char ch)
+{
+       return isalnum(ch) ||
+               ch == '-' || ch == '_' || ch == '.' || ch == '~';
+}
+
 int is_urlschemechar(int first_flag, int ch)
 {
        /*
diff --git a/url.h b/url.h
index 2a27c3427763b210b123b56c1e6553f8012f00bc..e644c3c809602833dd42eed4376a115547f1f1b2 100644 (file)
--- a/url.h
+++ b/url.h
@@ -21,4 +21,11 @@ char *url_decode_parameter_value(const char **query);
 void end_url_with_slash(struct strbuf *buf, const char *url);
 void str_end_url_with_slash(const char *url, char **dest);
 
+/*
+ * The set of unreserved characters as per STD66 (RFC3986) is
+ * '[A-Za-z0-9-._~]'. These characters are safe to appear in URI
+ * components without percent-encoding.
+ */
+int is_rfc3986_unreserved(char ch);
+
 #endif /* URL_H */