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