Skip to content

Commit 0c1df3f

Browse files
10ne1gitster
authored andcommitted
builtin/credential-store: move is_rfc3986_unreserved to url.[ch]
is_rfc3986_unreserved() was moved to credential-store.c and was made static by f898543 (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 by submodule.c in the next commit. Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 69fe57e commit 0c1df3f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

builtin/credential-store.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "path.h"
88
#include "string-list.h"
99
#include "parse-options.h"
10+
#include "url.h"
1011
#include "write-or-die.h"
1112

1213
static struct lock_file credential_lock;
@@ -76,12 +77,6 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
7677
die_errno("unable to write credential store");
7778
}
7879

79-
static int is_rfc3986_unreserved(char ch)
80-
{
81-
return isalnum(ch) ||
82-
ch == '-' || ch == '_' || ch == '.' || ch == '~';
83-
}
84-
8580
static int is_rfc3986_reserved_or_unreserved(char ch)
8681
{
8782
if (is_rfc3986_unreserved(ch))

url.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
#include "strbuf.h"
44
#include "url.h"
55

6+
/*
7+
* The set of unreserved characters as per STD66 (RFC3986) is
8+
* '[A-Za-z0-9-._~]'. These characters are safe to appear in URI
9+
* components without percent-encoding.
10+
*/
11+
int is_rfc3986_unreserved(char ch)
12+
{
13+
return isalnum(ch) ||
14+
ch == '-' || ch == '_' || ch == '.' || ch == '~';
15+
}
16+
617
int is_urlschemechar(int first_flag, int ch)
718
{
819
/*

url.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ char *url_decode_parameter_value(const char **query);
2121
void end_url_with_slash(struct strbuf *buf, const char *url);
2222
void str_end_url_with_slash(const char *url, char **dest);
2323

24+
int is_rfc3986_unreserved(char ch);
25+
2426
#endif /* URL_H */

0 commit comments

Comments
 (0)