Files
git/list-objects-filter.h
Siddharth Shrimali ba07f620d5 list-objects-filter: add list_objects_filter__filter_oidset()
The existing filter entry point, list_objects_filter__filter_object(),
is built around the object-walk path: it expects traversal context and
provisional omit sets, and is meant to be called as objects are
visited during a walk. A caller that already has a set of OIDs in hand
and only wants to know which ones a filter would select has no usable
entry point into the filter API.

--drop-filtered is exactly such a caller: it collects promisor blobs
into an oidset and needs to know which of them exceed the filter
threshold, without performing an object walk.

Add a helper, list_objects_filter__filter_oidset(), that takes a set
of OIDs and populates an "omitted" set with those that would be
filtered out by the given filter options. Only blob:limit=N filters
are supported for now.

This helper does not actually reuse the existing filter machinery.
It reimplements the blob:limit size check directly. That machinery
is tied to the object-walk path and cannot easily be driven
from a plain oidset. A NEEDSWORK comment marks this so the helper can
later be refactored to reuse the real filter logic instead of
duplicating it.

OBJECT_INFO_SKIP_FETCH_OBJECT is passed when reading object info so
the helper never triggers a lazy fetch.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Siddharth Asthana <siddharthasthana31@gmail.com>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-08-06 10:44:41 -07:00

114 lines
3.8 KiB
C

#ifndef LIST_OBJECTS_FILTER_H
#define LIST_OBJECTS_FILTER_H
struct list_objects_filter_options;
struct object;
struct oidset;
struct repository;
/*
* 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.
*
* _SKIP_TREE : Used in LOFS_BEGIN_TREE situation - indicates that
* the tree's children should not be iterated over. This
* is used as an optimization when all children will
* definitely be ignored.
*
* 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,
LOFR_SKIP_TREE = 1<<2,
};
enum list_objects_filter_situation {
LOFS_COMMIT,
LOFS_TAG,
LOFS_BEGIN_TREE,
LOFS_END_TREE,
LOFS_BLOB
};
struct filter;
/*
* Constructor for the set of defined list-objects filters.
* The `omitted` set is optional. It is populated with objects that the
* filter excludes. This set should not be considered finalized until
* after list_objects_filter__free is called on the returned `struct
* filter *`.
*/
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,
struct filter *filter);
/*
* Destroys `filter` and finalizes the `omitted` set, if present. Does
* nothing if `filter` is null.
*/
void list_objects_filter__free(struct filter *filter);
/*
* Given a set of OIDs in 'in', populate 'omitted' with those that
* would be filtered by 'opts'. Currently only blob:limit=N is
* supported. Objects that cannot be read are silently skipped.
*
* NEEDSWORK: this reimplements the blob:limit size check rather than
* reusing the existing filter machinery. See the matching comment in
* list-objects-filter.c.
*
* Return 0 on success, -1 if the filter is not supported.
*/
int list_objects_filter__filter_oidset(struct repository *r,
struct list_objects_filter_options *opts,
const struct oidset *in,
struct oidset *omitted);
#endif /* LIST_OBJECTS_FILTER_H */