Skip to content

Commit 568324f

Browse files
committed
Merge branch 'js/partial-urlmatch'
The same as js/partial-urlmatch-2.17, built on more recent codebase to avoid unnecessary merge conflicts. * js/partial-urlmatch: credential: handle `credential.<partial-URL>.<key>` again credential: optionally allow partial URLs in credential_from_url_gently()
2 parents da05cac + cd93e6c commit 568324f

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

credential.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ static int select_all(const struct urlmatch_item *a,
8686
return 0;
8787
}
8888

89+
static int match_partial_url(const char *url, void *cb)
90+
{
91+
struct credential *c = cb;
92+
struct credential want = CREDENTIAL_INIT;
93+
int matches = 0;
94+
95+
if (credential_from_potentially_partial_url(&want, url) < 0)
96+
warning(_("skipping credential lookup for key: credential.%s"),
97+
url);
98+
else
99+
matches = credential_match(&want, c);
100+
credential_clear(&want);
101+
102+
return matches;
103+
}
104+
89105
static void credential_apply_config(struct credential *c)
90106
{
91107
char *normalized_url;
@@ -105,6 +121,7 @@ static void credential_apply_config(struct credential *c)
105121
config.collect_fn = credential_config_callback;
106122
config.cascade_fn = NULL;
107123
config.select_fn = select_all;
124+
config.fallback_match_fn = match_partial_url;
108125
config.cb = c;
109126

110127
credential_format(c, &url);

urlmatch.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,14 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
572572

573573
config_url = xmemdupz(key, dot - key);
574574
norm_url = url_normalize_1(config_url, &norm_info, 1);
575+
if (norm_url)
576+
retval = match_urls(url, &norm_info, &matched);
577+
else if (collect->fallback_match_fn)
578+
retval = collect->fallback_match_fn(config_url,
579+
collect->cb);
580+
else
581+
retval = 0;
575582
free(config_url);
576-
if (!norm_url)
577-
return 0;
578-
retval = match_urls(url, &norm_info, &matched);
579583
free(norm_url);
580584
if (!retval)
581585
return 0;

urlmatch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ struct urlmatch_config {
5959
* specificity rules) than existing.
6060
*/
6161
int (*select_fn)(const struct urlmatch_item *found, const struct urlmatch_item *existing);
62+
/*
63+
* An optional callback to allow e.g. for partial URLs; it shall
64+
* return 1 or 0 depending whether `url` matches or not.
65+
*/
66+
int (*fallback_match_fn)(const char *url, void *cb);
6267
};
6368

6469
int urlmatch_config_entry(const char *var, const char *value, void *cb);

0 commit comments

Comments
 (0)