list-objects: support for skipping tree traversal
[git] / list-objects-filter.h
1 #ifndef LIST_OBJECTS_FILTER_H
2 #define LIST_OBJECTS_FILTER_H
3
4 /*
5  * During list-object traversal we allow certain objects to be
6  * filtered (omitted) from the result.  The active filter uses
7  * these result values to guide list-objects.
8  *
9  * _ZERO      : Do nothing with the object at this time.  It may
10  *              be revisited if it appears in another place in
11  *              the tree or in another commit during the overall
12  *              traversal.
13  *
14  * _MARK_SEEN : Mark this object as "SEEN" in the object flags.
15  *              This will prevent it from being revisited during
16  *              the remainder of the traversal.  This DOES NOT
17  *              imply that it will be included in the results.
18  *
19  * _DO_SHOW   : Show this object in the results (call show() on it).
20  *              In general, objects should only be shown once, but
21  *              this result DOES NOT imply that we mark it SEEN.
22  *
23  * _SKIP_TREE : Used in LOFS_BEGIN_TREE situation - indicates that
24  *              the tree's children should not be iterated over. This
25  *              is used as an optimization when all children will
26  *              definitely be ignored.
27  *
28  * Most of the time, you want the combination (_MARK_SEEN | _DO_SHOW)
29  * but they can be used independently, such as when sparse-checkout
30  * pattern matching is being applied.
31  *
32  * A _MARK_SEEN without _DO_SHOW can be called a hard-omit -- the
33  * object is not shown and will never be reconsidered (unless a
34  * previous iteration has already shown it).
35  *
36  * A _DO_SHOW without _MARK_SEEN can be used, for example, to
37  * include a directory, but then revisit it to selectively include
38  * or omit objects within it.
39  *
40  * A _ZERO can be called a provisional-omit -- the object is NOT shown,
41  * but *may* be revisited (if the object appears again in the traversal).
42  * Therefore, it will be omitted from the results *unless* a later
43  * iteration causes it to be shown.
44  */
45 enum list_objects_filter_result {
46         LOFR_ZERO      = 0,
47         LOFR_MARK_SEEN = 1<<0,
48         LOFR_DO_SHOW   = 1<<1,
49         LOFR_SKIP_TREE = 1<<2,
50 };
51
52 enum list_objects_filter_situation {
53         LOFS_BEGIN_TREE,
54         LOFS_END_TREE,
55         LOFS_BLOB
56 };
57
58 typedef enum list_objects_filter_result (*filter_object_fn)(
59         enum list_objects_filter_situation filter_situation,
60         struct object *obj,
61         const char *pathname,
62         const char *filename,
63         void *filter_data);
64
65 typedef void (*filter_free_fn)(void *filter_data);
66
67 /*
68  * Constructor for the set of defined list-objects filters.
69  * Returns a generic "void *filter_data".
70  *
71  * The returned "filter_fn" will be used by traverse_commit_list()
72  * to filter the results.
73  *
74  * The returned "filter_free_fn" is a destructor for the
75  * filter_data.
76  */
77 void *list_objects_filter__init(
78         struct oidset *omitted,
79         struct list_objects_filter_options *filter_options,
80         filter_object_fn *filter_fn,
81         filter_free_fn *filter_free_fn);
82
83 #endif /* LIST_OBJECTS_FILTER_H */