Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-05-06 00:54:29 +0300
committerJunio C Hamano <gitster@pobox.com>2020-05-06 00:54:30 +0300
commit568324f31ba6cec13532e420117d312db65ddd80 (patch)
tree749064792c8d2f6e22e932c165373839cef17803
parentda05cacd8a4e7c3d6d8c84aa2c1d45684717ac95 (diff)
parentcd93e6c029026cc3da466ddc53927e85b7e7041e (diff)
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()
-rw-r--r--credential.c17
-rw-r--r--urlmatch.c10
-rw-r--r--urlmatch.h5
3 files changed, 29 insertions, 3 deletions
diff --git a/credential.c b/credential.c
index c19322d98f..d8d226b97e 100644
--- a/credential.c
+++ b/credential.c
@@ -86,6 +86,22 @@ static int select_all(const struct urlmatch_item *a,
return 0;
}
+static int match_partial_url(const char *url, void *cb)
+{
+ struct credential *c = cb;
+ struct credential want = CREDENTIAL_INIT;
+ int matches = 0;
+
+ if (credential_from_potentially_partial_url(&want, url) < 0)
+ warning(_("skipping credential lookup for key: credential.%s"),
+ url);
+ else
+ matches = credential_match(&want, c);
+ credential_clear(&want);
+
+ return matches;
+}
+
static void credential_apply_config(struct credential *c)
{
char *normalized_url;
@@ -105,6 +121,7 @@ static void credential_apply_config(struct credential *c)
config.collect_fn = credential_config_callback;
config.cascade_fn = NULL;
config.select_fn = select_all;
+ config.fallback_match_fn = match_partial_url;
config.cb = c;
credential_format(c, &url);
diff --git a/urlmatch.c b/urlmatch.c
index 29272a5c4f..33a2ccd306 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -572,10 +572,14 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
config_url = xmemdupz(key, dot - key);
norm_url = url_normalize_1(config_url, &norm_info, 1);
+ if (norm_url)
+ retval = match_urls(url, &norm_info, &matched);
+ else if (collect->fallback_match_fn)
+ retval = collect->fallback_match_fn(config_url,
+ collect->cb);
+ else
+ retval = 0;
free(config_url);
- if (!norm_url)
- return 0;
- retval = match_urls(url, &norm_info, &matched);
free(norm_url);
if (!retval)
return 0;
diff --git a/urlmatch.h b/urlmatch.h
index 2407520731..6ff42f81b0 100644
--- a/urlmatch.h
+++ b/urlmatch.h
@@ -59,6 +59,11 @@ struct urlmatch_config {
* specificity rules) than existing.
*/
int (*select_fn)(const struct urlmatch_item *found, const struct urlmatch_item *existing);
+ /*
+ * An optional callback to allow e.g. for partial URLs; it shall
+ * return 1 or 0 depending whether `url` matches or not.
+ */
+ int (*fallback_match_fn)(const char *url, void *cb);
};
int urlmatch_config_entry(const char *var, const char *value, void *cb);