SubmittingPatches: use of older maintenance tracks is an exception
[git.git] / list-objects-filter-options.h
blobf6206125868eb06cc448182418c23b3e4c9e95a6
1 #ifndef LIST_OBJECTS_FILTER_OPTIONS_H
2 #define LIST_OBJECTS_FILTER_OPTIONS_H
4 #include "gettext.h"
5 #include "object.h"
6 #include "string-list.h"
7 #include "strbuf.h"
9 struct option;
12 * The list of defined filters for list-objects.
14 enum list_objects_filter_choice {
15 LOFC_DISABLED = 0,
16 LOFC_BLOB_NONE,
17 LOFC_BLOB_LIMIT,
18 LOFC_TREE_DEPTH,
19 LOFC_SPARSE_OID,
20 LOFC_OBJECT_TYPE,
21 LOFC_COMBINE,
22 LOFC__COUNT /* must be last */
26 * Returns a configuration key suitable for describing the given object filter,
27 * e.g.: "blob:none", "combine", etc.
29 const char *list_object_filter_config_name(enum list_objects_filter_choice c);
31 struct list_objects_filter_options {
33 * 'filter_spec' is the raw argument value given on the command line
34 * or protocol request. (The part after the "--keyword=".) For
35 * commands that launch filtering sub-processes, or for communication
36 * over the network, don't use this value; use the result of
37 * expand_list_objects_filter_spec() instead.
38 * To get the raw filter spec given by the user, use the result of
39 * list_objects_filter_spec().
41 struct strbuf filter_spec;
44 * 'choice' is determined by parsing the filter-spec. This indicates
45 * the filtering algorithm to use.
47 enum list_objects_filter_choice choice;
50 * Choice is LOFC_DISABLED because "--no-filter" was requested.
52 unsigned int no_filter : 1;
55 * BEGIN choice-specific parsed values from within the filter-spec. Only
56 * some values will be defined for any given choice.
59 char *sparse_oid_name;
60 unsigned long blob_limit_value;
61 unsigned long tree_exclude_depth;
62 enum object_type object_type;
64 /* LOFC_COMBINE values */
66 /* This array contains all the subfilters which this filter combines. */
67 size_t sub_nr, sub_alloc;
68 struct list_objects_filter_options *sub;
71 * END choice-specific parsed values.
75 #define LIST_OBJECTS_FILTER_INIT { .filter_spec = STRBUF_INIT }
76 void list_objects_filter_init(struct list_objects_filter_options *filter_options);
79 * Parse value of the argument to the "filter" keyword.
80 * On the command line this looks like:
81 * --filter=<arg>
82 * and in the pack protocol as:
83 * "filter" SP <arg>
85 * The filter keyword will be used by many commands.
86 * See Documentation/rev-list-options.txt for allowed values for <arg>.
88 * Capture the given arg as the "filter_spec". This can be forwarded to
89 * subordinate commands when necessary (although it's better to pass it through
90 * expand_list_objects_filter_spec() first). We also "intern" the arg for the
91 * convenience of the current command.
93 int gently_parse_list_objects_filter(
94 struct list_objects_filter_options *filter_options,
95 const char *arg,
96 struct strbuf *errbuf);
98 void list_objects_filter_die_if_populated(
99 struct list_objects_filter_options *filter_options);
102 * Parses the filter spec string given by arg and either (1) simply places the
103 * result in filter_options if it is not yet populated or (2) combines it with
104 * the filter already in filter_options if it is already populated. In the case
105 * of (2), the filter specs are combined as if specified with 'combine:'.
107 * Dies and prints a user-facing message if an error occurs.
109 void parse_list_objects_filter(
110 struct list_objects_filter_options *filter_options,
111 const char *arg);
114 * The opt->value to opt_parse_list_objects_filter() is either a
115 * "struct list_objects_filter_option *" when using
116 * OPT_PARSE_LIST_OBJECTS_FILTER().
118 int opt_parse_list_objects_filter(const struct option *opt,
119 const char *arg, int unset);
121 #define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
122 OPT_CALLBACK(0, "filter", (fo), N_("args"), \
123 N_("object filtering"), opt_parse_list_objects_filter)
126 * Translates abbreviated numbers in the filter's filter_spec into their
127 * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024").
128 * Returns a string owned by the list_objects_filter_options object.
130 * This form should be used instead of the raw list_objects_filter_spec()
131 * value when communicating with a remote process or subprocess.
133 const char *expand_list_objects_filter_spec(
134 struct list_objects_filter_options *filter);
137 * Returns the filter spec string more or less in the form as the user
138 * entered it. This form of the filter_spec can be used in user-facing
139 * messages. Returns a string owned by the list_objects_filter_options
140 * object.
142 const char *list_objects_filter_spec(
143 struct list_objects_filter_options *filter);
145 void list_objects_filter_release(
146 struct list_objects_filter_options *filter_options);
148 static inline void list_objects_filter_set_no_filter(
149 struct list_objects_filter_options *filter_options)
151 list_objects_filter_release(filter_options);
152 filter_options->no_filter = 1;
155 void partial_clone_register(
156 const char *remote,
157 struct list_objects_filter_options *filter_options);
158 void partial_clone_get_default_filter_spec(
159 struct list_objects_filter_options *filter_options,
160 const char *remote);
162 void list_objects_filter_copy(
163 struct list_objects_filter_options *dest,
164 const struct list_objects_filter_options *src);
166 #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */