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

Function do_match

tree-walk.c:1021–1215  ·  view source on GitHub ↗

* Is a tree entry interesting given the pathspec we have? * * Pre-condition: either baselen == 0 (i.e. empty path) * or base[baselen-1] == '/' (i.e. with trailing slash). */

Source from the content-addressed store, hash-verified

1019 * or base[baselen-1] == '/' (i.e. with trailing slash).
1020 */
1021static enum interesting do_match(struct index_state *istate,
1022 const struct name_entry *entry,
1023 struct strbuf *base,
1024 const struct pathspec *ps,
1025 int exclude)
1026{
1027 int i;
1028 int pathlen, baselen = base->len;
1029 enum interesting never_interesting = ps->has_wildcard ?
1030 entry_not_interesting : all_entries_not_interesting;
1031
1032 GUARD_PATHSPEC(ps,
1033 PATHSPEC_FROMTOP |
1034 PATHSPEC_MAXDEPTH |
1035 PATHSPEC_LITERAL |
1036 PATHSPEC_GLOB |
1037 PATHSPEC_ICASE |
1038 PATHSPEC_EXCLUDE |
1039 PATHSPEC_ATTR);
1040
1041 if (!ps->nr) {
1042 if (!ps->recursive ||
1043 !(ps->magic & PATHSPEC_MAXDEPTH) ||
1044 ps->max_depth == -1)
1045 return all_entries_interesting;
1046 return within_depth(base->buf, baselen,
1047 !!S_ISDIR(entry->mode),
1048 ps->max_depth) ?
1049 entry_interesting : entry_not_interesting;
1050 }
1051
1052 pathlen = tree_entry_len(entry);
1053
1054 for (i = ps->nr - 1; i >= 0; i--) {
1055 const struct pathspec_item *item = ps->items+i;
1056 const char *match = item->match;
1057 const char *base_str = base->buf;
1058 int matchlen = item->len, matched = 0;
1059
1060 if ((!exclude && item->magic & PATHSPEC_EXCLUDE) ||
1061 ( exclude && !(item->magic & PATHSPEC_EXCLUDE)))
1062 continue;
1063
1064 if (baselen >= matchlen) {
1065 /* If it doesn't match, move along... */
1066 if (!match_dir_prefix(item, base_str, match, matchlen))
1067 goto match_wildcards;
1068
1069 if (!ps->recursive ||
1070 !(ps->magic & PATHSPEC_MAXDEPTH) ||
1071 ps->max_depth == -1) {
1072 if (!item->attr_match_nr)
1073 return all_entries_interesting;
1074 else
1075 goto interesting;
1076 }
1077
1078 if (within_depth(base_str + matchlen + 1,

Callers 1

tree_entry_interestingFunction · 0.85

Calls 11

within_depthFunction · 0.85
tree_entry_lenFunction · 0.85
match_dir_prefixFunction · 0.85
basecmpFunction · 0.85
match_entryFunction · 0.85
git_fnmatchFunction · 0.85
ps_strncmpFunction · 0.85
match_wildcard_baseFunction · 0.85
strbuf_addFunction · 0.85
strbuf_setlenFunction · 0.85
match_pathspec_attrsFunction · 0.85

Tested by

no test coverage detected