aboutsummaryrefslogtreecommitdiff
path: root/list-objects-filter.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2026-02-16 14:23:12 +0100
committerJunio C Hamano <gitster@pobox.com>2026-02-17 11:46:40 -0800
commitcd1a89838ad6753830afeed4ad8319e567b6e43d (patch)
treea77aede1faaf0cbd55f8eb324512077266afee36 /list-objects-filter.c
parent190438b62fa5624077c2ee48065f47e1a56d01a7 (diff)
downloadgit-cd1a89838ad6753830afeed4ad8319e567b6e43d.tar.xz
list-objects-filter-options: support 'auto' mode for --filter
In a following commit, we are going to allow passing "auto" as a <filterspec> to the `--filter=<filterspec>` option, but only for some commands. Other commands that support the `--filter=<filterspec>` option should still die() when 'auto' is passed. Let's set up the "list-objects-filter-options.{c,h}" infrastructure to support that: - Add a new `unsigned int allow_auto_filter : 1;` flag to `struct list_objects_filter_options` which specifies if "auto" is accepted or not by the current command. - Change gently_parse_list_objects_filter() to parse "auto" if it's accepted. - Make sure we die() if "auto" is combined with another filter. - Update list_objects_filter_release() to preserve the allow_auto_filter flag, as this function is often called (via opt_parse_list_objects_filter) to reset the struct before parsing a new value. Let's also update `list-objects-filter.c` to recognize the new `LOFC_AUTO` choice. Since "auto" must be resolved to a concrete filter before filtering actually begins, initializing a filter with `LOFC_AUTO` is invalid and will trigger a BUG(). Note that ideally combining "auto" with "auto" could be allowed, but in practice, it's probably not worth the added code complexity. And if we really want it, nothing prevents us to allow it in future work. If we ever want to give a meaning to combining "auto" with a different filter too, nothing prevents us to do that in future work either. Also note that the new `allow_auto_filter` flag depends on the command, not user choices, so it should be reset to the command default when `struct list_objects_filter_options` instances are reset. While at it, let's add a new "u-list-objects-filter-options.c" file for `struct list_objects_filter_options` related unit tests. For now it only tests gently_parse_list_objects_filter() though. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'list-objects-filter.c')
-rw-r--r--list-objects-filter.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/list-objects-filter.c b/list-objects-filter.c
index acd65ebb73..78316e7f90 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -745,6 +745,13 @@ static void filter_combine__init(
filter->finalize_omits_fn = filter_combine__finalize_omits;
}
+static void filter_auto__init(
+ struct list_objects_filter_options *filter_options UNUSED,
+ struct filter *filter UNUSED)
+{
+ BUG("LOFC_AUTO should have been resolved before initializing the filter");
+}
+
typedef void (*filter_init_fn)(
struct list_objects_filter_options *filter_options,
struct filter *filter);
@@ -760,6 +767,7 @@ static filter_init_fn s_filters[] = {
filter_sparse_oid__init,
filter_object_type__init,
filter_combine__init,
+ filter_auto__init,
};
struct filter *list_objects_filter__init(