refspec: clarify function naming and documentation

Rename `match_name_with_pattern()` to `match_refname_with_pattern()` to better reflect its purpose and improve documentation comment clarity. The previous function name and parameter names were inconsistent, making it harder to understand their roles in refspec matching. - Rename parameters: - `key` -> `pattern` (globbing pattern to match) - `name` -> `refname` (refname to check) - `value` -> `replacement` (replacement mapping pattern) Signed-off-by: Meet Soni <meetsoni3017@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Meet Soni committed Feb 15, 2025 at 14:15 UTC 044b6f04f23d6c7e3c3750c9829db96b71470874
3 files changed +25 -24
refspec.c
+17 -17
@@ -269,28 +269,28 @@ void refspec_ref_prefixes(const struct refspec *rs,
269 }
270 }
271
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)
274 {
275 - const char *kstar = strchr(key, '*');
275 + const char *kstar = strchr(pattern, '*');
276 size_t klen;
277 size_t ksuffixlen;
278 size_t namelen;
279 int ret;
280 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;
283 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) {
288 struct strbuf sb = STRBUF_INIT;
289 - const char *vstar = strchr(value, '*');
289 + const char *vstar = strchr(replacement, '*');
290 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);
294 strbuf_addstr(&sb, vstar + 1);
295 *result = strbuf_detach(&sb, NULL);
296 }
@@ -301,7 +301,7 @@ static int refspec_match(const struct refspec_item *refspec,
301 const char *name)
302 {
303 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);
305
306 return !strcmp(refspec->src, name);
307 }
@@ -352,7 +352,7 @@ static int refspec_find_negative_match(struct refspec *rs, struct refspec_item *
352 const char *key = refspec->dst ? refspec->dst : refspec->src;
353 const char *value = refspec->src;
354
355 - if (match_name_with_pattern(key, needle, value, &expn_name))
355 + if (match_refname_with_pattern(key, needle, value, &expn_name))
356 string_list_append_nodup(&reversed, expn_name);
357 } else if (refspec->matching) {
358 /* For the special matching refspec, any query should match */
@@ -397,7 +397,7 @@ void refspec_find_all_matches(struct refspec *rs,
397 if (!refspec->dst || refspec->negative)
398 continue;
399 if (refspec->pattern) {
400 - if (match_name_with_pattern(key, needle, value, result))
400 + if (match_refname_with_pattern(key, needle, value, result))
401 string_list_append_nodup(results, *result);
402 } else if (!strcmp(needle, key)) {
403 string_list_append(results, value);
@@ -426,7 +426,7 @@ int refspec_find_match(struct refspec *rs, struct refspec_item *query)
426 if (!refspec->dst || refspec->negative)
427 continue;
428 if (refspec->pattern) {
429 - if (match_name_with_pattern(key, needle, value, result)) {
429 + if (match_refname_with_pattern(key, needle, value, result)) {
430 query->force = refspec->force;
431 return 0;
432 }
refspec.h
+5 -4
@@ -75,11 +75,12 @@ void refspec_ref_prefixes(const struct refspec *rs,
75 int refname_matches_negative_refspec_item(const char *refname, struct refspec *rs);
76
77 /*
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.
81 */
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);
84
85 /*
86 * Queries a refspec for a match and updates the query item.
remote.c
+3 -3
@@ -1322,9 +1322,9 @@ static char *get_ref_match(const struct refspec *rs, const struct ref *ref,
1322 const char *dst_side = item->dst ? item->dst : item->src;
1323 int match;
1324 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);
1326 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);
1328 if (match) {
1329 matching_refs = i;
1330 break;
@@ -1942,7 +1942,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
1942
1943 if (strchr(ref->name, '^'))
1944 continue; /* a dereference item */
1945 - if (match_name_with_pattern(refspec->src, ref->name,
1945 + if (match_refname_with_pattern(refspec->src, ref->name,
1946 refspec->dst, &expn_name) &&
1947 !ignore_symref_update(expn_name, &scratch)) {
1948 struct ref *cpy = copy_ref(ref);