]> git.ipfire.org Git - thirdparty/git.git/blame - list-objects-filter-options.h
rebase: allow overriding the maximal length of the generated labels
[thirdparty/git.git] / list-objects-filter-options.h
CommitLineData
25ec7bca
JH
1#ifndef LIST_OBJECTS_FILTER_OPTIONS_H
2#define LIST_OBJECTS_FILTER_OPTIONS_H
3
f394e093 4#include "gettext.h"
a64215b6 5#include "object.h"
cf9ceb5a 6#include "string-list.h"
a64215b6 7#include "strbuf.h"
25ec7bca 8
c4d9c793
SG
9struct option;
10
25ec7bca
JH
11/*
12 * The list of defined filters for list-objects.
13 */
14enum list_objects_filter_choice {
15 LOFC_DISABLED = 0,
16 LOFC_BLOB_NONE,
17 LOFC_BLOB_LIMIT,
c813a7c3 18 LOFC_TREE_DEPTH,
25ec7bca 19 LOFC_SPARSE_OID,
b0c42a53 20 LOFC_OBJECT_TYPE,
e987df5f 21 LOFC_COMBINE,
25ec7bca
JH
22 LOFC__COUNT /* must be last */
23};
24
b9ea2147
TB
25/*
26 * Returns a configuration key suitable for describing the given object filter,
27 * e.g.: "blob:none", "combine", etc.
28 */
29const char *list_object_filter_config_name(enum list_objects_filter_choice c);
30
25ec7bca
JH
31struct 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
87c2d9d3
JS
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.
cf9ceb5a
MD
38 * To get the raw filter spec given by the user, use the result of
39 * list_objects_filter_spec().
25ec7bca 40 */
c54980ab 41 struct strbuf filter_spec;
25ec7bca
JH
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
aa57b871
JH
49 /*
50 * Choice is LOFC_DISABLED because "--no-filter" was requested.
51 */
52 unsigned int no_filter : 1;
53
25ec7bca 54 /*
e987df5f
MD
55 * BEGIN choice-specific parsed values from within the filter-spec. Only
56 * some values will be defined for any given choice.
25ec7bca 57 */
e987df5f 58
4c96a775 59 char *sparse_oid_name;
25ec7bca 60 unsigned long blob_limit_value;
c813a7c3 61 unsigned long tree_exclude_depth;
b0c42a53 62 enum object_type object_type;
e987df5f
MD
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 */
25ec7bca
JH
73};
74
c54980ab 75#define LIST_OBJECTS_FILTER_INIT { .filter_spec = STRBUF_INIT }
2a01bded
JK
76void list_objects_filter_init(struct list_objects_filter_options *filter_options);
77
105c6f14
DS
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 */
93int gently_parse_list_objects_filter(
94 struct list_objects_filter_options *filter_options,
95 const char *arg,
96 struct strbuf *errbuf);
97
489fc9ee
MD
98void 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 */
90d21f9e 109void parse_list_objects_filter(
25ec7bca
JH
110 struct list_objects_filter_options *filter_options,
111 const char *arg);
112
5cb28270
ÆAB
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().
5cb28270 117 */
25ec7bca
JH
118int opt_parse_list_objects_filter(const struct option *opt,
119 const char *arg, int unset);
120
121#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
d4f70368
RS
122 OPT_CALLBACK(0, "filter", (fo), N_("args"), \
123 N_("object filtering"), opt_parse_list_objects_filter)
25ec7bca 124
87c2d9d3
JS
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").
cf9ceb5a 128 * Returns a string owned by the list_objects_filter_options object.
87c2d9d3 129 *
cf9ceb5a
MD
130 * This form should be used instead of the raw list_objects_filter_spec()
131 * value when communicating with a remote process or subprocess.
87c2d9d3 132 */
cf9ceb5a
MD
133const 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 */
142const char *list_objects_filter_spec(
143 struct list_objects_filter_options *filter);
87c2d9d3 144
4875c979
JH
145void list_objects_filter_release(
146 struct list_objects_filter_options *filter_options);
147
aa57b871
JH
148static 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
1e1e39b3
JH
155void partial_clone_register(
156 const char *remote,
cf9ceb5a 157 struct list_objects_filter_options *filter_options);
1e1e39b3 158void partial_clone_get_default_filter_spec(
fa3d1b63
CC
159 struct list_objects_filter_options *filter_options,
160 const char *remote);
1e1e39b3 161
4a4c3f9b
DS
162void list_objects_filter_copy(
163 struct list_objects_filter_options *dest,
164 const struct list_objects_filter_options *src);
165
25ec7bca 166#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */