Skip to content

Commit 2ebbe2b

Browse files
committed
Merge branch 'ms/rename-match-name-with-pattern'
Code renaming. * ms/rename-match-name-with-pattern: refspec: clarify function naming and documentation
2 parents 0921809 + 044b6f0 commit 2ebbe2b

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

refspec.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -269,28 +269,28 @@ void refspec_ref_prefixes(const struct refspec *rs,
269269
}
270270
}
271271

272-
int match_name_with_pattern(const char *key, const char *name,
273-
const char *value, char **result)
272+
int match_refname_with_pattern(const char *pattern, const char *refname,
273+
const char *replacement, char **result)
274274
{
275-
const char *kstar = strchr(key, '*');
275+
const char *kstar = strchr(pattern, '*');
276276
size_t klen;
277277
size_t ksuffixlen;
278278
size_t namelen;
279279
int ret;
280280
if (!kstar)
281-
die(_("key '%s' of pattern had no '*'"), key);
282-
klen = kstar - key;
281+
die(_("pattern '%s' has no '*'"), pattern);
282+
klen = kstar - pattern;
283283
ksuffixlen = strlen(kstar + 1);
284-
namelen = strlen(name);
285-
ret = !strncmp(name, key, klen) && namelen >= klen + ksuffixlen &&
286-
!memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen);
287-
if (ret && value) {
284+
namelen = strlen(refname);
285+
ret = !strncmp(refname, pattern, klen) && namelen >= klen + ksuffixlen &&
286+
!memcmp(refname + namelen - ksuffixlen, kstar + 1, ksuffixlen);
287+
if (ret && replacement) {
288288
struct strbuf sb = STRBUF_INIT;
289-
const char *vstar = strchr(value, '*');
289+
const char *vstar = strchr(replacement, '*');
290290
if (!vstar)
291-
die(_("value '%s' of pattern has no '*'"), value);
292-
strbuf_add(&sb, value, vstar - value);
293-
strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
291+
die(_("replacement '%s' has no '*'"), replacement);
292+
strbuf_add(&sb, replacement, vstar - replacement);
293+
strbuf_add(&sb, refname + klen, namelen - klen - ksuffixlen);
294294
strbuf_addstr(&sb, vstar + 1);
295295
*result = strbuf_detach(&sb, NULL);
296296
}
@@ -301,7 +301,7 @@ static int refspec_match(const struct refspec_item *refspec,
301301
const char *name)
302302
{
303303
if (refspec->pattern)
304-
return match_name_with_pattern(refspec->src, name, NULL, NULL);
304+
return match_refname_with_pattern(refspec->src, name, NULL, NULL);
305305

306306
return !strcmp(refspec->src, name);
307307
}
@@ -352,7 +352,7 @@ static int refspec_find_negative_match(struct refspec *rs, struct refspec_item *
352352
const char *key = refspec->dst ? refspec->dst : refspec->src;
353353
const char *value = refspec->src;
354354

355-
if (match_name_with_pattern(key, needle, value, &expn_name))
355+
if (match_refname_with_pattern(key, needle, value, &expn_name))
356356
string_list_append_nodup(&reversed, expn_name);
357357
} else if (refspec->matching) {
358358
/* For the special matching refspec, any query should match */
@@ -397,7 +397,7 @@ void refspec_find_all_matches(struct refspec *rs,
397397
if (!refspec->dst || refspec->negative)
398398
continue;
399399
if (refspec->pattern) {
400-
if (match_name_with_pattern(key, needle, value, result))
400+
if (match_refname_with_pattern(key, needle, value, result))
401401
string_list_append_nodup(results, *result);
402402
} else if (!strcmp(needle, key)) {
403403
string_list_append(results, value);
@@ -426,7 +426,7 @@ int refspec_find_match(struct refspec *rs, struct refspec_item *query)
426426
if (!refspec->dst || refspec->negative)
427427
continue;
428428
if (refspec->pattern) {
429-
if (match_name_with_pattern(key, needle, value, result)) {
429+
if (match_refname_with_pattern(key, needle, value, result)) {
430430
query->force = refspec->force;
431431
return 0;
432432
}

refspec.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ void refspec_ref_prefixes(const struct refspec *rs,
7575
int refname_matches_negative_refspec_item(const char *refname, struct refspec *rs);
7676

7777
/*
78-
* Checks whether a name matches a pattern and optionally generates a result.
79-
* Returns 1 if the name matches the pattern, 0 otherwise.
78+
* Checks if a refname matches a globbing refspec pattern.
79+
* If replacement is provided, computes the corresponding mapped refname.
80+
* Returns 1 if refname matches pattern, 0 otherwise.
8081
*/
81-
int match_name_with_pattern(const char *key, const char *name,
82-
const char *value, char **result);
82+
int match_refname_with_pattern(const char *pattern, const char *refname,
83+
const char *replacement, char **result);
8384

8485
/*
8586
* Queries a refspec for a match and updates the query item.

remote.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,9 +1322,9 @@ static char *get_ref_match(const struct refspec *rs, const struct ref *ref,
13221322
const char *dst_side = item->dst ? item->dst : item->src;
13231323
int match;
13241324
if (direction == FROM_SRC)
1325-
match = match_name_with_pattern(item->src, ref->name, dst_side, &name);
1325+
match = match_refname_with_pattern(item->src, ref->name, dst_side, &name);
13261326
else
1327-
match = match_name_with_pattern(dst_side, ref->name, item->src, &name);
1327+
match = match_refname_with_pattern(dst_side, ref->name, item->src, &name);
13281328
if (match) {
13291329
matching_refs = i;
13301330
break;
@@ -1942,7 +1942,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
19421942

19431943
if (strchr(ref->name, '^'))
19441944
continue; /* a dereference item */
1945-
if (match_name_with_pattern(refspec->src, ref->name,
1945+
if (match_refname_with_pattern(refspec->src, ref->name,
19461946
refspec->dst, &expn_name) &&
19471947
!ignore_symref_update(expn_name, &scratch)) {
19481948
struct ref *cpy = copy_ref(ref);

0 commit comments

Comments
 (0)