MCPcopy Index your code
hub / github.com/git/git / match_refname_with_pattern

Function match_refname_with_pattern

refspec.c:298–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

296}
297
298int match_refname_with_pattern(const char *pattern, const char *refname,
299 const char *replacement, char **result)
300{
301 const char *kstar = strchr(pattern, '*');
302 size_t klen;
303 size_t ksuffixlen;
304 size_t namelen;
305 int ret;
306 if (!kstar)
307 die(_("pattern '%s' has no '*'"), pattern);
308 klen = kstar - pattern;
309 ksuffixlen = strlen(kstar + 1);
310 namelen = strlen(refname);
311 ret = !strncmp(refname, pattern, klen) && namelen >= klen + ksuffixlen &&
312 !memcmp(refname + namelen - ksuffixlen, kstar + 1, ksuffixlen);
313 if (ret && replacement) {
314 struct strbuf sb = STRBUF_INIT;
315 const char *vstar = strchr(replacement, '*');
316 if (!vstar)
317 die(_("replacement '%s' has no '*'"), replacement);
318 strbuf_add(&sb, replacement, vstar - replacement);
319 strbuf_add(&sb, refname + klen, namelen - klen - ksuffixlen);
320 strbuf_addstr(&sb, vstar + 1);
321 *result = strbuf_detach(&sb, NULL);
322 }
323 return ret;
324}
325
326static int refspec_match(const struct refspec_item *refspec,
327 const char *name)

Callers 6

refspec_matchFunction · 0.85
refspec_find_all_matchesFunction · 0.85
refspec_find_matchFunction · 0.85
get_ref_matchFunction · 0.85
get_expanded_mapFunction · 0.85

Calls 4

strbuf_addFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_detachFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected