MCPcopy Create free account
hub / github.com/git/git / match_pathname

Function match_pathname

dir.c:1352–1415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1350}
1351
1352int match_pathname(const char *pathname, int pathlen,
1353 const char *base, int baselen,
1354 const char *pattern, int prefix, int patternlen)
1355{
1356 const char *name;
1357 int namelen;
1358
1359 /*
1360 * match with FNM_PATHNAME; the pattern has base implicitly
1361 * in front of it.
1362 */
1363 if (*pattern == '/') {
1364 pattern++;
1365 patternlen--;
1366 prefix--;
1367 }
1368
1369 /*
1370 * baselen does not count the trailing slash. base[] may or
1371 * may not end with a trailing slash though.
1372 */
1373 if (pathlen < baselen + 1 ||
1374 (baselen && pathname[baselen] != '/') ||
1375 fspathncmp(pathname, base, baselen))
1376 return 0;
1377
1378 namelen = baselen ? pathlen - baselen - 1 : pathlen;
1379 name = pathname + pathlen - namelen;
1380
1381 if (prefix) {
1382 /*
1383 * if the non-wildcard part is longer than the
1384 * remaining pathname, surely it cannot match.
1385 */
1386 if (prefix > namelen)
1387 return 0;
1388
1389 if (fspathncmp(pattern, name, prefix))
1390 return 0;
1391
1392 /*
1393 * If the whole pattern did not have a wildcard,
1394 * then our prefix match is all we need; we
1395 * do not need to call fnmatch at all.
1396 */
1397 if (patternlen == prefix && namelen == prefix)
1398 return 1;
1399
1400 /*
1401 * Retain one character of the prefix to
1402 * pass to fnmatch, which lets it distinguish
1403 * the start of a directory component correctly.
1404 */
1405 prefix--;
1406 pattern += prefix;
1407 patternlen -= prefix;
1408 name += prefix;
1409 namelen -= prefix;

Callers 2

path_matchesFunction · 0.85

Calls 1

fnmatch_icase_memFunction · 0.85

Tested by

no test coverage detected