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

Function path_matches_pattern_list

dir.c:1477–1550  ·  view source on GitHub ↗

* Scan the list of patterns to determine if the ordered list * of patterns matches on 'pathname'. * * Return 1 for a match, 0 for not matched and -1 for undecided. */

Source from the content-addressed store, hash-verified

1475 * Return 1 for a match, 0 for not matched and -1 for undecided.
1476 */
1477enum pattern_match_result path_matches_pattern_list(
1478 const char *pathname, int pathlen,
1479 const char *basename, int *dtype,
1480 struct pattern_list *pl,
1481 struct index_state *istate)
1482{
1483 struct path_pattern *pattern;
1484 struct strbuf parent_pathname = STRBUF_INIT;
1485 int result = NOT_MATCHED;
1486 size_t slash_pos;
1487
1488 if (!pl->use_cone_patterns) {
1489 pattern = last_matching_pattern_from_list(pathname, pathlen, basename,
1490 dtype, pl, istate);
1491 if (pattern) {
1492 if (pattern->flags & PATTERN_FLAG_NEGATIVE)
1493 return NOT_MATCHED;
1494 else
1495 return MATCHED;
1496 }
1497
1498 return UNDECIDED;
1499 }
1500
1501 if (pl->full_cone)
1502 return MATCHED;
1503
1504 strbuf_addch(&parent_pathname, '/');
1505 strbuf_add(&parent_pathname, pathname, pathlen);
1506
1507 /*
1508 * Directory entries are matched if and only if a file
1509 * contained immediately within them is matched. For the
1510 * case of a directory entry, modify the path to create
1511 * a fake filename within this directory, allowing us to
1512 * use the file-base matching logic in an equivalent way.
1513 */
1514 if (parent_pathname.len > 0 &&
1515 parent_pathname.buf[parent_pathname.len - 1] == '/') {
1516 slash_pos = parent_pathname.len - 1;
1517 strbuf_add(&parent_pathname, "-", 1);
1518 } else {
1519 const char *slash_ptr = strrchr(parent_pathname.buf, '/');
1520 slash_pos = slash_ptr ? slash_ptr - parent_pathname.buf : 0;
1521 }
1522
1523 if (hashmap_contains_path(&pl->recursive_hashmap,
1524 &parent_pathname)) {
1525 result = MATCHED_RECURSIVE;
1526 goto done;
1527 }
1528
1529 if (!slash_pos) {
1530 /* include every file in root */
1531 result = MATCHED;
1532 goto done;
1533 }
1534

Callers 7

clear_ce_flags_dirFunction · 0.85
clear_ce_flags_1Function · 0.85
filter_sparseFunction · 0.85
add_path_to_indexFunction · 0.85
expand_indexFunction · 0.85
add_tree_entriesFunction · 0.85

Calls 7

strbuf_addchFunction · 0.85
strbuf_addFunction · 0.85
hashmap_contains_pathFunction · 0.85
strbuf_setlenFunction · 0.85
hashmap_contains_parentFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected