diff options
author | Derrick Stolee <dstolee@microsoft.com> | 2019-09-03 21:04:58 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-09-06 00:05:12 +0300 |
commit | 468ce99b77a0efaf1ace4c31a7b0a7d036fd9ca1 (patch) | |
tree | 7399ea6e2d1eea755b78587f2c9a9c6f3fe7365f /list-objects-filter.c | |
parent | 65edd96aecdee2cd4d16a7c17ae9f723c3fe61a4 (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 <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'list-objects-filter.c')
-rw-r--r-- | list-objects-filter.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/list-objects-filter.c b/list-objects-filter.c index ccd58e61c3..d624f1c898 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -328,12 +328,12 @@ static void filter_blobs_limit__init( */ struct frame { /* - * defval is the usual default include/exclude value that + * default_match is the usual default include/exclude value that * should be inherited as we recurse into directories based * upon pattern matching of the directory itself or of a * containing directory. */ - int defval; + enum pattern_match_result default_match; /* * 1 if the directory (recursively) contains any provisionally @@ -363,8 +363,9 @@ static enum list_objects_filter_result filter_sparse( void *filter_data_) { struct filter_sparse_data *filter_data = filter_data_; - int val, dtype; + int dtype; struct frame *frame; + enum pattern_match_result match; switch (filter_situation) { default: @@ -373,15 +374,15 @@ static enum list_objects_filter_result filter_sparse( case LOFS_BEGIN_TREE: assert(obj->type == OBJ_TREE); dtype = DT_DIR; - val = is_excluded_from_list(pathname, strlen(pathname), - filename, &dtype, &filter_data->pl, - r->index); - if (val < 0) - val = filter_data->array_frame[filter_data->nr - 1].defval; + match = path_matches_pattern_list(pathname, strlen(pathname), + filename, &dtype, &filter_data->pl, + r->index); + if (match == UNDECIDED) + match = filter_data->array_frame[filter_data->nr - 1].default_match; ALLOC_GROW(filter_data->array_frame, filter_data->nr + 1, filter_data->alloc); - filter_data->array_frame[filter_data->nr].defval = val; + filter_data->array_frame[filter_data->nr].default_match = match; filter_data->array_frame[filter_data->nr].child_prov_omit = 0; filter_data->nr++; @@ -435,12 +436,12 @@ static enum list_objects_filter_result filter_sparse( frame = &filter_data->array_frame[filter_data->nr - 1]; dtype = DT_REG; - val = is_excluded_from_list(pathname, strlen(pathname), + match = path_matches_pattern_list(pathname, strlen(pathname), filename, &dtype, &filter_data->pl, r->index); - if (val < 0) - val = frame->defval; - if (val > 0) { + if (match == UNDECIDED) + match = frame->default_match; + if (match == MATCHED) { if (omits) oidset_remove(omits, &obj->oid); return LOFR_MARK_SEEN | LOFR_DO_SHOW; @@ -487,7 +488,7 @@ static void filter_sparse_oid__init( die("could not load filter specification"); ALLOC_GROW(d->array_frame, d->nr + 1, d->alloc); - d->array_frame[d->nr].defval = 0; /* default to include */ + d->array_frame[d->nr].default_match = 0; /* default to include */ d->array_frame[d->nr].child_prov_omit = 0; d->nr++; |