summaryrefslogtreecommitdiff
path: root/refspec.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-03-12 11:55:05 -0700
committerJunio C Hamano <gitster@pobox.com>2025-03-12 11:55:05 -0700
commit7c42ab2c92a54adf0573de36ea29e5bcb819c7da (patch)
treeead8ff7ad6d5b3b42d30ca3dc34f0f1cd69126c3 /refspec.c
parentb838bf1938926a7a900166136d995d86f8a00e24 (diff)
parent87d297f48367737444810f8c3e76ef88cb6aa4e3 (diff)
Merge branch 'ps/refname-avail-check-optim' into kn/non-transactional-batch-updates
* ps/refname-avail-check-optim: (43 commits) refs: reuse iterators when determining refname availability refs/iterator: implement seeking for files iterators refs/iterator: implement seeking for packed-ref iterators refs/iterator: implement seeking for ref-cache iterators refs/iterator: implement seeking for reftable iterators refs/iterator: implement seeking for merged iterators refs/iterator: provide infrastructure to re-seek iterators refs/iterator: separate lifecycle from iteration refs: stop re-verifying common prefixes for availability refs/files: batch refname availability checks for initial transactions refs/files: batch refname availability checks for normal transactions refs/reftable: batch refname availability checks refs: introduce function to batch refname availability checks builtin/update-ref: skip ambiguity checks when parsing object IDs object-name: allow skipping ambiguity checks in `get_oid()` family object-name: introduce `repo_get_oid_with_flags()` Git 2.49-rc0 The fourteenth batch mailmap: fix check-mailmap with full mailmap line The thirteenth batch ...
Diffstat (limited to 'refspec.c')
-rw-r--r--refspec.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/refspec.c b/refspec.c
index 3d6cf4dc92..4cb80b5208 100644
--- a/refspec.c
+++ b/refspec.c
@@ -269,28 +269,28 @@ void refspec_ref_prefixes(const struct refspec *rs,
}
}
-int match_name_with_pattern(const char *key, const char *name,
- const char *value, char **result)
+int match_refname_with_pattern(const char *pattern, const char *refname,
+ const char *replacement, char **result)
{
- const char *kstar = strchr(key, '*');
+ const char *kstar = strchr(pattern, '*');
size_t klen;
size_t ksuffixlen;
size_t namelen;
int ret;
if (!kstar)
- die(_("key '%s' of pattern had no '*'"), key);
- klen = kstar - key;
+ die(_("pattern '%s' has no '*'"), pattern);
+ klen = kstar - pattern;
ksuffixlen = strlen(kstar + 1);
- namelen = strlen(name);
- ret = !strncmp(name, key, klen) && namelen >= klen + ksuffixlen &&
- !memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen);
- if (ret && value) {
+ namelen = strlen(refname);
+ ret = !strncmp(refname, pattern, klen) && namelen >= klen + ksuffixlen &&
+ !memcmp(refname + namelen - ksuffixlen, kstar + 1, ksuffixlen);
+ if (ret && replacement) {
struct strbuf sb = STRBUF_INIT;
- const char *vstar = strchr(value, '*');
+ const char *vstar = strchr(replacement, '*');
if (!vstar)
- die(_("value '%s' of pattern has no '*'"), value);
- strbuf_add(&sb, value, vstar - value);
- strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
+ die(_("replacement '%s' has no '*'"), replacement);
+ strbuf_add(&sb, replacement, vstar - replacement);
+ strbuf_add(&sb, refname + klen, namelen - klen - ksuffixlen);
strbuf_addstr(&sb, vstar + 1);
*result = strbuf_detach(&sb, NULL);
}
@@ -301,7 +301,7 @@ static int refspec_match(const struct refspec_item *refspec,
const char *name)
{
if (refspec->pattern)
- return match_name_with_pattern(refspec->src, name, NULL, NULL);
+ return match_refname_with_pattern(refspec->src, name, NULL, NULL);
return !strcmp(refspec->src, name);
}
@@ -352,7 +352,7 @@ static int refspec_find_negative_match(struct refspec *rs, struct refspec_item *
const char *key = refspec->dst ? refspec->dst : refspec->src;
const char *value = refspec->src;
- if (match_name_with_pattern(key, needle, value, &expn_name))
+ if (match_refname_with_pattern(key, needle, value, &expn_name))
string_list_append_nodup(&reversed, expn_name);
} else if (refspec->matching) {
/* For the special matching refspec, any query should match */
@@ -397,7 +397,7 @@ void refspec_find_all_matches(struct refspec *rs,
if (!refspec->dst || refspec->negative)
continue;
if (refspec->pattern) {
- if (match_name_with_pattern(key, needle, value, result))
+ if (match_refname_with_pattern(key, needle, value, result))
string_list_append_nodup(results, *result);
} else if (!strcmp(needle, key)) {
string_list_append(results, value);
@@ -426,7 +426,7 @@ int refspec_find_match(struct refspec *rs, struct refspec_item *query)
if (!refspec->dst || refspec->negative)
continue;
if (refspec->pattern) {
- if (match_name_with_pattern(key, needle, value, result)) {
+ if (match_refname_with_pattern(key, needle, value, result)) {
query->force = refspec->force;
return 0;
}