blob: 55fab8563d20a5a7ada0e9fd1215303808c5853d [file] [log] [blame]
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +00001#ifndef LIST_OBJECTS_FILTER_OPTIONS_H
2#define LIST_OBJECTS_FILTER_OPTIONS_H
3
Elijah Newrenf394e092023-03-21 06:25:54 +00004#include "gettext.h"
Elijah Newrena64215b2023-02-24 00:09:30 +00005#include "object.h"
Elijah Newrena64215b2023-02-24 00:09:30 +00006#include "strbuf.h"
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +00007
SZEDER Gáborc4d9c792023-03-19 17:27:12 +01008struct option;
9
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000010/*
11 * The list of defined filters for list-objects.
12 */
13enum list_objects_filter_choice {
14 LOFC_DISABLED = 0,
15 LOFC_BLOB_NONE,
16 LOFC_BLOB_LIMIT,
Matthew DeVorec813a7c2019-01-08 18:59:13 -080017 LOFC_TREE_DEPTH,
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000018 LOFC_SPARSE_OID,
Patrick Steinhardtb0c42a52021-04-19 13:46:53 +020019 LOFC_OBJECT_TYPE,
Matthew DeVoree987df52019-06-27 15:54:08 -070020 LOFC_COMBINE,
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000021 LOFC__COUNT /* must be last */
22};
23
Taylor Blaub9ea2142020-07-31 16:26:26 -040024/*
25 * Returns a configuration key suitable for describing the given object filter,
26 * e.g.: "blob:none", "combine", etc.
27 */
28const char *list_object_filter_config_name(enum list_objects_filter_choice c);
29
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000030struct list_objects_filter_options {
31 /*
32 * 'filter_spec' is the raw argument value given on the command line
33 * or protocol request. (The part after the "--keyword=".) For
Josh Steadmon87c2d9d2019-01-07 16:17:09 -080034 * commands that launch filtering sub-processes, or for communication
35 * over the network, don't use this value; use the result of
36 * expand_list_objects_filter_spec() instead.
Matthew DeVorecf9ceb52019-06-27 15:54:10 -070037 * To get the raw filter spec given by the user, use the result of
38 * list_objects_filter_spec().
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000039 */
Jeff Kingc54980a2022-09-11 01:03:31 -040040 struct strbuf filter_spec;
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000041
42 /*
43 * 'choice' is determined by parsing the filter-spec. This indicates
44 * the filtering algorithm to use.
45 */
46 enum list_objects_filter_choice choice;
47
48 /*
Jeff Hostetleraa57b872017-12-08 15:58:50 +000049 * Choice is LOFC_DISABLED because "--no-filter" was requested.
50 */
51 unsigned int no_filter : 1;
52
53 /*
Matthew DeVoree987df52019-06-27 15:54:08 -070054 * BEGIN choice-specific parsed values from within the filter-spec. Only
55 * some values will be defined for any given choice.
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000056 */
Matthew DeVoree987df52019-06-27 15:54:08 -070057
Jeff King4c96a772019-09-15 12:12:44 -040058 char *sparse_oid_name;
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000059 unsigned long blob_limit_value;
Matthew DeVorec813a7c2019-01-08 18:59:13 -080060 unsigned long tree_exclude_depth;
Patrick Steinhardtb0c42a52021-04-19 13:46:53 +020061 enum object_type object_type;
Matthew DeVoree987df52019-06-27 15:54:08 -070062
63 /* LOFC_COMBINE values */
64
65 /* This array contains all the subfilters which this filter combines. */
66 size_t sub_nr, sub_alloc;
67 struct list_objects_filter_options *sub;
68
69 /*
70 * END choice-specific parsed values.
71 */
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000072};
73
Jeff Kingc54980a2022-09-11 01:03:31 -040074#define LIST_OBJECTS_FILTER_INIT { .filter_spec = STRBUF_INIT }
Jeff King2a01bde2022-09-11 01:03:07 -040075void list_objects_filter_init(struct list_objects_filter_options *filter_options);
76
Derrick Stolee105c6f12022-03-09 16:01:39 +000077/*
78 * Parse value of the argument to the "filter" keyword.
79 * On the command line this looks like:
80 * --filter=<arg>
81 * and in the pack protocol as:
82 * "filter" SP <arg>
83 *
84 * The filter keyword will be used by many commands.
85 * See Documentation/rev-list-options.txt for allowed values for <arg>.
86 *
87 * Capture the given arg as the "filter_spec". This can be forwarded to
88 * subordinate commands when necessary (although it's better to pass it through
89 * expand_list_objects_filter_spec() first). We also "intern" the arg for the
90 * convenience of the current command.
91 */
92int gently_parse_list_objects_filter(
93 struct list_objects_filter_options *filter_options,
94 const char *arg,
95 struct strbuf *errbuf);
96
Matthew DeVore489fc9e2019-06-27 15:54:12 -070097void list_objects_filter_die_if_populated(
98 struct list_objects_filter_options *filter_options);
99
100/*
101 * Parses the filter spec string given by arg and either (1) simply places the
102 * result in filter_options if it is not yet populated or (2) combines it with
103 * the filter already in filter_options if it is already populated. In the case
104 * of (2), the filter specs are combined as if specified with 'combine:'.
105 *
106 * Dies and prints a user-facing message if an error occurs.
107 */
Matthew DeVore90d21f92019-06-27 15:54:14 -0700108void parse_list_objects_filter(
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000109 struct list_objects_filter_options *filter_options,
110 const char *arg);
111
Ævar Arnfjörð Bjarmason5cb28272022-03-28 17:43:18 +0200112/**
113 * The opt->value to opt_parse_list_objects_filter() is either a
114 * "struct list_objects_filter_option *" when using
115 * OPT_PARSE_LIST_OBJECTS_FILTER().
Ævar Arnfjörð Bjarmason5cb28272022-03-28 17:43:18 +0200116 */
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000117int opt_parse_list_objects_filter(const struct option *opt,
118 const char *arg, int unset);
119
120#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
René Scharfed4f70362022-11-29 13:26:44 +0100121 OPT_CALLBACK(0, "filter", (fo), N_("args"), \
122 N_("object filtering"), opt_parse_list_objects_filter)
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000123
Josh Steadmon87c2d9d2019-01-07 16:17:09 -0800124/*
125 * Translates abbreviated numbers in the filter's filter_spec into their
126 * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024").
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700127 * Returns a string owned by the list_objects_filter_options object.
Josh Steadmon87c2d9d2019-01-07 16:17:09 -0800128 *
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700129 * This form should be used instead of the raw list_objects_filter_spec()
130 * value when communicating with a remote process or subprocess.
Josh Steadmon87c2d9d2019-01-07 16:17:09 -0800131 */
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700132const char *expand_list_objects_filter_spec(
133 struct list_objects_filter_options *filter);
134
135/*
136 * Returns the filter spec string more or less in the form as the user
137 * entered it. This form of the filter_spec can be used in user-facing
138 * messages. Returns a string owned by the list_objects_filter_options
139 * object.
140 */
141const char *list_objects_filter_spec(
142 struct list_objects_filter_options *filter);
Josh Steadmon87c2d9d2019-01-07 16:17:09 -0800143
Jeff Hostetler4875c972017-12-05 16:50:13 +0000144void list_objects_filter_release(
145 struct list_objects_filter_options *filter_options);
146
Jeff Hostetleraa57b872017-12-08 15:58:50 +0000147static inline void list_objects_filter_set_no_filter(
148 struct list_objects_filter_options *filter_options)
149{
150 list_objects_filter_release(filter_options);
151 filter_options->no_filter = 1;
152}
153
Jeff Hostetler1e1e39b2017-12-08 15:58:45 +0000154void partial_clone_register(
155 const char *remote,
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700156 struct list_objects_filter_options *filter_options);
Jeff Hostetler1e1e39b2017-12-08 15:58:45 +0000157void partial_clone_get_default_filter_spec(
Christian Couderfa3d1b62019-06-25 15:40:32 +0200158 struct list_objects_filter_options *filter_options,
159 const char *remote);
Jeff Hostetler1e1e39b2017-12-08 15:58:45 +0000160
Derrick Stolee4a4c3f92022-03-09 16:01:32 +0000161void list_objects_filter_copy(
162 struct list_objects_filter_options *dest,
163 const struct list_objects_filter_options *src);
164
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000165#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */