]> git.ipfire.org Git - thirdparty/git.git/blob - list-objects-filter-options.h
rebase: allow overriding the maximal length of the generated labels
[thirdparty/git.git] / list-objects-filter-options.h
1 #ifndef LIST_OBJECTS_FILTER_OPTIONS_H
2 #define LIST_OBJECTS_FILTER_OPTIONS_H
3
4 #include "gettext.h"
5 #include "object.h"
6 #include "string-list.h"
7 #include "strbuf.h"
8
9 struct option;
10
11 /*
12 * The list of defined filters for list-objects.
13 */
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 */
23 };
24
25 /*
26 * Returns a configuration key suitable for describing the given object filter,
27 * e.g.: "blob:none", "combine", etc.
28 */
29 const char *list_object_filter_config_name(enum list_objects_filter_choice c);
30
31 struct list_objects_filter_options {
32 /*
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().
40 */
41 struct strbuf filter_spec;
42
43 /*
44 * 'choice' is determined by parsing the filter-spec. This indicates
45 * the filtering algorithm to use.
46 */
47 enum list_objects_filter_choice choice;
48
49 /*
50 * Choice is LOFC_DISABLED because "--no-filter" was requested.
51 */
52 unsigned int no_filter : 1;
53
54 /*
55 * BEGIN choice-specific parsed values from within the filter-spec. Only
56 * some values will be defined for any given choice.
57 */
58
59 char *sparse_oid_name;
60 unsigned long blob_limit_value;
61 unsigned long tree_exclude_depth;
62 enum object_type object_type;
63
64 /* LOFC_COMBINE values */
65
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;
69
70 /*
71 * END choice-specific parsed values.
72 */
73 };
74
75 #define LIST_OBJECTS_FILTER_INIT { .filter_spec = STRBUF_INIT }
76 void list_objects_filter_init(struct list_objects_filter_options *filter_options);
77
78 /*
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>
84 *
85 * The filter keyword will be used by many commands.
86 * See Documentation/rev-list-options.txt for allowed values for <arg>.
87 *
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.
92 */
93 int gently_parse_list_objects_filter(
94 struct list_objects_filter_options *filter_options,
95 const char *arg,
96 struct strbuf *errbuf);
97
98 void list_objects_filter_die_if_populated(
99 struct list_objects_filter_options *filter_options);
100
101 /*
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:'.
106 *
107 * Dies and prints a user-facing message if an error occurs.
108 */
109 void parse_list_objects_filter(
110 struct list_objects_filter_options *filter_options,
111 const char *arg);
112
113 /**
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().
117 */
118 int opt_parse_list_objects_filter(const struct option *opt,
119 const char *arg, int unset);
120
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)
124
125 /*
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.
129 *
130 * This form should be used instead of the raw list_objects_filter_spec()
131 * value when communicating with a remote process or subprocess.
132 */
133 const char *expand_list_objects_filter_spec(
134 struct list_objects_filter_options *filter);
135
136 /*
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.
141 */
142 const char *list_objects_filter_spec(
143 struct list_objects_filter_options *filter);
144
145 void list_objects_filter_release(
146 struct list_objects_filter_options *filter_options);
147
148 static inline void list_objects_filter_set_no_filter(
149 struct list_objects_filter_options *filter_options)
150 {
151 list_objects_filter_release(filter_options);
152 filter_options->no_filter = 1;
153 }
154
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);
161
162 void list_objects_filter_copy(
163 struct list_objects_filter_options *dest,
164 const struct list_objects_filter_options *src);
165
166 #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */