path: root/dir.c
diff options
authorDerrick Stolee <>2019-09-03 18:04:58 (GMT)
committerJunio C Hamano <>2019-09-05 21:05:12 (GMT)
commit468ce99b77a0efaf1ace4c31a7b0a7d036fd9ca1 (patch)
tree7399ea6e2d1eea755b78587f2c9a9c6f3fe7365f /dir.c
parent65edd96aecdee2cd4d16a7c17ae9f723c3fe61a4 (diff)
unpack-trees: rename 'is_excluded_from_list()'
The first consumer of pattern-matching filenames was the .gitignore feature. In that context, storing a list of patterns as a 'struct exclude_list' makes sense. However, the sparse-checkout feature then adopted these structures and methods, but with the opposite meaning: these patterns match the files that should be included! Now that this library is renamed to use 'struct pattern_list' and 'struct pattern', we can now rename the method used by the sparse-checkout feature to determine which paths should appear in the working directory. The method is_excluded_from_list() is only used by the sparse-checkout logic in unpack-trees and list-objects-filter. The confusing part is that it returned 1 for "excluded" (i.e. it matches the list of exclusions) but that really manes that the path matched the list of patterns for _inclusion_ in the working directory. Rename the method to be path_matches_pattern_list() and have it return an explicit 'enum pattern_match_result'. Here, the values MATCHED = 1, UNMATCHED = 0, and UNDECIDED = -1 agree with the previous integer values. This shift allows future consumers to better understand what the retur values mean, and provides more type checking for handling those values. Signed-off-by: Derrick Stolee <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'dir.c')
1 files changed, 17 insertions, 8 deletions
diff --git a/dir.c b/dir.c
index b057bd3..34972ab 100644
--- a/dir.c
+++ b/dir.c
@@ -1072,19 +1072,28 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname
- * Scan the list and let the last match determine the fate.
- * Return 1 for exclude, 0 for include and -1 for undecided.
+ * 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.
-int is_excluded_from_list(const char *pathname,
- int pathlen, const char *basename, int *dtype,
- struct pattern_list *pl, struct index_state *istate)
+enum pattern_match_result path_matches_pattern_list(
+ const char *pathname, int pathlen,
+ const char *basename, int *dtype,
+ struct pattern_list *pl,
+ struct index_state *istate)
struct path_pattern *pattern;
pattern = last_matching_pattern_from_list(pathname, pathlen, basename,
dtype, pl, istate);
- if (pattern)
- return pattern->flags & PATTERN_FLAG_NEGATIVE ? 0 : 1;
- return -1; /* undecided */
+ if (pattern) {
+ if (pattern->flags & PATTERN_FLAG_NEGATIVE)
+ return NOT_MATCHED;
+ else
+ return MATCHED;
+ }
+ return UNDECIDED;
static struct path_pattern *last_matching_pattern_from_lists(