summaryrefslogtreecommitdiff
path: root/list-objects-filter.h
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2017-11-21 20:58:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-22 05:11:57 (GMT)
commit25ec7bcac044057900a0f3c9a8d6ccbb41a066bc (patch)
tree115a72c755c0578349d3cf08bef0b0883fd4153e /list-objects-filter.h
parentc3a9ad311793e16f6f5c5dcc3559133700c70288 (diff)
downloadgit-25ec7bcac044057900a0f3c9a8d6ccbb41a066bc.zip
git-25ec7bcac044057900a0f3c9a8d6ccbb41a066bc.tar.gz
git-25ec7bcac044057900a0f3c9a8d6ccbb41a066bc.tar.bz2
list-objects: filter objects in traverse_commit_list
Create traverse_commit_list_filtered() and add filtering interface to allow certain objects to be omitted from the traversal. Update traverse_commit_list() to be a wrapper for the above with a null filter to minimize the number of callers that needed to be changed. Object filtering will be used in a future commit by rev-list and pack-objects for partial clone and fetch to omit unwanted objects from the result. traverse_bitmap_commit_list() does not work with filtering. If a packfile bitmap is present, it will not be used. It should be possible to extend such support in the future (at least to simple filters that do not require object pathnames), but that is beyond the scope of this patch series. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'list-objects-filter.h')
-rw-r--r--list-objects-filter.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/list-objects-filter.h b/list-objects-filter.h
new file mode 100644
index 0000000..a963d02
--- /dev/null
+++ b/list-objects-filter.h
@@ -0,0 +1,77 @@
+#ifndef LIST_OBJECTS_FILTER_H
+#define LIST_OBJECTS_FILTER_H
+
+/*
+ * During list-object traversal we allow certain objects to be
+ * filtered (omitted) from the result. The active filter uses
+ * these result values to guide list-objects.
+ *
+ * _ZERO : Do nothing with the object at this time. It may
+ * be revisited if it appears in another place in
+ * the tree or in another commit during the overall
+ * traversal.
+ *
+ * _MARK_SEEN : Mark this object as "SEEN" in the object flags.
+ * This will prevent it from being revisited during
+ * the remainder of the traversal. This DOES NOT
+ * imply that it will be included in the results.
+ *
+ * _DO_SHOW : Show this object in the results (call show() on it).
+ * In general, objects should only be shown once, but
+ * this result DOES NOT imply that we mark it SEEN.
+ *
+ * Most of the time, you want the combination (_MARK_SEEN | _DO_SHOW)
+ * but they can be used independently, such as when sparse-checkout
+ * pattern matching is being applied.
+ *
+ * A _MARK_SEEN without _DO_SHOW can be called a hard-omit -- the
+ * object is not shown and will never be reconsidered (unless a
+ * previous iteration has already shown it).
+ *
+ * A _DO_SHOW without _MARK_SEEN can be used, for example, to
+ * include a directory, but then revisit it to selectively include
+ * or omit objects within it.
+ *
+ * A _ZERO can be called a provisional-omit -- the object is NOT shown,
+ * but *may* be revisited (if the object appears again in the traversal).
+ * Therefore, it will be omitted from the results *unless* a later
+ * iteration causes it to be shown.
+ */
+enum list_objects_filter_result {
+ LOFR_ZERO = 0,
+ LOFR_MARK_SEEN = 1<<0,
+ LOFR_DO_SHOW = 1<<1,
+};
+
+enum list_objects_filter_situation {
+ LOFS_BEGIN_TREE,
+ LOFS_END_TREE,
+ LOFS_BLOB
+};
+
+typedef enum list_objects_filter_result (*filter_object_fn)(
+ 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);
+
+/*
+ * 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);
+
+#endif /* LIST_OBJECTS_FILTER_H */