diff options
author | Matthew DeVore <matvore@google.com> | 2019-06-27 22:54:05 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-06-28 15:41:53 (GMT) |
commit | 9430147ca0aab0189d7e52df97b95a0985fc0c8a (patch) | |
tree | 063bbf5b2d710466c1e34bdffcdc2b3a59f5fc71 /list-objects-filter.h | |
parent | 8dca754b1e874719a732bc9ab7b0e14b21b1bc10 (diff) | |
download | git-9430147ca0aab0189d7e52df97b95a0985fc0c8a.zip git-9430147ca0aab0189d7e52df97b95a0985fc0c8a.tar.gz git-9430147ca0aab0189d7e52df97b95a0985fc0c8a.tar.bz2 |
list-objects-filter: encapsulate filter components
Encapsulate filter_fn, filter_free_fn, and filter_data into their own
opaque struct.
Due to opaqueness, filter_fn and filter_free_fn can no longer be
accessed directly by users. Currently, all usages of filter_fn are
guarded by a necessary check:
(obj->flags & NOT_USER_GIVEN) && filter_fn
Take the opportunity to include this check into the new function
list_objects_filter__filter_object(), so that we no longer need to write
this check at every caller of the filter function.
Also, the init functions in list-objects-filter.c no longer need to
confusingly return the filter constituents in various places (filter_fn
and filter_free_fn as out parameters, and filter_data as the function's
return value); they can just initialize the "struct filter" passed in.
Helped-by: Jeff Hostetler <git@jeffhostetler.com>
Helped-by: Jonathan Tan <jonathantanmy@google.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Matthew DeVore <matvore@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'list-objects-filter.h')
-rw-r--r-- | list-objects-filter.h | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/list-objects-filter.h b/list-objects-filter.h index 1d45a4a..6908954 100644 --- a/list-objects-filter.h +++ b/list-objects-filter.h @@ -60,30 +60,27 @@ enum list_objects_filter_situation { LOFS_BLOB }; -typedef enum list_objects_filter_result (*filter_object_fn)( +struct filter; + +/* Constructor for the set of defined list-objects filters. */ +struct filter *list_objects_filter__init( + struct oidset *omitted, + struct list_objects_filter_options *filter_options); + +/* + * Lets `filter` decide how to handle the `obj`. If `filter` is NULL, this + * function behaves as expected if no filter is configured: all objects are + * included. + */ +enum list_objects_filter_result list_objects_filter__filter_object( struct repository *r, enum list_objects_filter_situation filter_situation, struct object *obj, const char *pathname, const char *filename, - void *filter_data); - -typedef void (*filter_free_fn)(void *filter_data); + struct filter *filter); -/* - * Constructor for the set of defined list-objects filters. - * Returns a generic "void *filter_data". - * - * The returned "filter_fn" will be used by traverse_commit_list() - * to filter the results. - * - * The returned "filter_free_fn" is a destructor for the - * filter_data. - */ -void *list_objects_filter__init( - struct oidset *omitted, - struct list_objects_filter_options *filter_options, - filter_object_fn *filter_fn, - filter_free_fn *filter_free_fn); +/* Destroys `filter`. Does nothing if `filter` is null. */ +void list_objects_filter__free(struct filter *filter); #endif /* LIST_OBJECTS_FILTER_H */ |