]>
Commit | Line | Data |
---|---|---|
25ec7bca JH |
1 | #ifndef LIST_OBJECTS_FILTER_OPTIONS_H |
2 | #define LIST_OBJECTS_FILTER_OPTIONS_H | |
3 | ||
a64215b6 | 4 | #include "object.h" |
25ec7bca | 5 | #include "parse-options.h" |
cf9ceb5a | 6 | #include "string-list.h" |
a64215b6 | 7 | #include "strbuf.h" |
25ec7bca JH |
8 | |
9 | /* | |
10 | * The list of defined filters for list-objects. | |
11 | */ | |
12 | enum list_objects_filter_choice { | |
13 | LOFC_DISABLED = 0, | |
14 | LOFC_BLOB_NONE, | |
15 | LOFC_BLOB_LIMIT, | |
c813a7c3 | 16 | LOFC_TREE_DEPTH, |
25ec7bca | 17 | LOFC_SPARSE_OID, |
b0c42a53 | 18 | LOFC_OBJECT_TYPE, |
e987df5f | 19 | LOFC_COMBINE, |
25ec7bca JH |
20 | LOFC__COUNT /* must be last */ |
21 | }; | |
22 | ||
b9ea2147 TB |
23 | /* |
24 | * Returns a configuration key suitable for describing the given object filter, | |
25 | * e.g.: "blob:none", "combine", etc. | |
26 | */ | |
27 | const char *list_object_filter_config_name(enum list_objects_filter_choice c); | |
28 | ||
25ec7bca JH |
29 | struct list_objects_filter_options { |
30 | /* | |
31 | * 'filter_spec' is the raw argument value given on the command line | |
32 | * or protocol request. (The part after the "--keyword=".) For | |
87c2d9d3 JS |
33 | * commands that launch filtering sub-processes, or for communication |
34 | * over the network, don't use this value; use the result of | |
35 | * expand_list_objects_filter_spec() instead. | |
cf9ceb5a MD |
36 | * To get the raw filter spec given by the user, use the result of |
37 | * list_objects_filter_spec(). | |
25ec7bca | 38 | */ |
c54980ab | 39 | struct strbuf filter_spec; |
25ec7bca JH |
40 | |
41 | /* | |
42 | * 'choice' is determined by parsing the filter-spec. This indicates | |
43 | * the filtering algorithm to use. | |
44 | */ | |
45 | enum list_objects_filter_choice choice; | |
46 | ||
aa57b871 JH |
47 | /* |
48 | * Choice is LOFC_DISABLED because "--no-filter" was requested. | |
49 | */ | |
50 | unsigned int no_filter : 1; | |
51 | ||
25ec7bca | 52 | /* |
e987df5f MD |
53 | * BEGIN choice-specific parsed values from within the filter-spec. Only |
54 | * some values will be defined for any given choice. | |
25ec7bca | 55 | */ |
e987df5f | 56 | |
4c96a775 | 57 | char *sparse_oid_name; |
25ec7bca | 58 | unsigned long blob_limit_value; |
c813a7c3 | 59 | unsigned long tree_exclude_depth; |
b0c42a53 | 60 | enum object_type object_type; |
e987df5f MD |
61 | |
62 | /* LOFC_COMBINE values */ | |
63 | ||
64 | /* This array contains all the subfilters which this filter combines. */ | |
65 | size_t sub_nr, sub_alloc; | |
66 | struct list_objects_filter_options *sub; | |
67 | ||
68 | /* | |
69 | * END choice-specific parsed values. | |
70 | */ | |
25ec7bca JH |
71 | }; |
72 | ||
c54980ab | 73 | #define LIST_OBJECTS_FILTER_INIT { .filter_spec = STRBUF_INIT } |
2a01bded JK |
74 | void list_objects_filter_init(struct list_objects_filter_options *filter_options); |
75 | ||
105c6f14 DS |
76 | /* |
77 | * Parse value of the argument to the "filter" keyword. | |
78 | * On the command line this looks like: | |
79 | * --filter=<arg> | |
80 | * and in the pack protocol as: | |
81 | * "filter" SP <arg> | |
82 | * | |
83 | * The filter keyword will be used by many commands. | |
84 | * See Documentation/rev-list-options.txt for allowed values for <arg>. | |
85 | * | |
86 | * Capture the given arg as the "filter_spec". This can be forwarded to | |
87 | * subordinate commands when necessary (although it's better to pass it through | |
88 | * expand_list_objects_filter_spec() first). We also "intern" the arg for the | |
89 | * convenience of the current command. | |
90 | */ | |
91 | int gently_parse_list_objects_filter( | |
92 | struct list_objects_filter_options *filter_options, | |
93 | const char *arg, | |
94 | struct strbuf *errbuf); | |
95 | ||
489fc9ee MD |
96 | void list_objects_filter_die_if_populated( |
97 | struct list_objects_filter_options *filter_options); | |
98 | ||
99 | /* | |
100 | * Parses the filter spec string given by arg and either (1) simply places the | |
101 | * result in filter_options if it is not yet populated or (2) combines it with | |
102 | * the filter already in filter_options if it is already populated. In the case | |
103 | * of (2), the filter specs are combined as if specified with 'combine:'. | |
104 | * | |
105 | * Dies and prints a user-facing message if an error occurs. | |
106 | */ | |
90d21f9e | 107 | void parse_list_objects_filter( |
25ec7bca JH |
108 | struct list_objects_filter_options *filter_options, |
109 | const char *arg); | |
110 | ||
5cb28270 ÆAB |
111 | /** |
112 | * The opt->value to opt_parse_list_objects_filter() is either a | |
113 | * "struct list_objects_filter_option *" when using | |
114 | * OPT_PARSE_LIST_OBJECTS_FILTER(). | |
5cb28270 | 115 | */ |
25ec7bca JH |
116 | int opt_parse_list_objects_filter(const struct option *opt, |
117 | const char *arg, int unset); | |
118 | ||
119 | #define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \ | |
d4f70368 RS |
120 | OPT_CALLBACK(0, "filter", (fo), N_("args"), \ |
121 | N_("object filtering"), opt_parse_list_objects_filter) | |
25ec7bca | 122 | |
87c2d9d3 JS |
123 | /* |
124 | * Translates abbreviated numbers in the filter's filter_spec into their | |
125 | * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024"). | |
cf9ceb5a | 126 | * Returns a string owned by the list_objects_filter_options object. |
87c2d9d3 | 127 | * |
cf9ceb5a MD |
128 | * This form should be used instead of the raw list_objects_filter_spec() |
129 | * value when communicating with a remote process or subprocess. | |
87c2d9d3 | 130 | */ |
cf9ceb5a MD |
131 | const char *expand_list_objects_filter_spec( |
132 | struct list_objects_filter_options *filter); | |
133 | ||
134 | /* | |
135 | * Returns the filter spec string more or less in the form as the user | |
136 | * entered it. This form of the filter_spec can be used in user-facing | |
137 | * messages. Returns a string owned by the list_objects_filter_options | |
138 | * object. | |
139 | */ | |
140 | const char *list_objects_filter_spec( | |
141 | struct list_objects_filter_options *filter); | |
87c2d9d3 | 142 | |
4875c979 JH |
143 | void list_objects_filter_release( |
144 | struct list_objects_filter_options *filter_options); | |
145 | ||
aa57b871 JH |
146 | static inline void list_objects_filter_set_no_filter( |
147 | struct list_objects_filter_options *filter_options) | |
148 | { | |
149 | list_objects_filter_release(filter_options); | |
150 | filter_options->no_filter = 1; | |
151 | } | |
152 | ||
1e1e39b3 JH |
153 | void partial_clone_register( |
154 | const char *remote, | |
cf9ceb5a | 155 | struct list_objects_filter_options *filter_options); |
1e1e39b3 | 156 | void partial_clone_get_default_filter_spec( |
fa3d1b63 CC |
157 | struct list_objects_filter_options *filter_options, |
158 | const char *remote); | |
1e1e39b3 | 159 | |
4a4c3f9b DS |
160 | void list_objects_filter_copy( |
161 | struct list_objects_filter_options *dest, | |
162 | const struct list_objects_filter_options *src); | |
163 | ||
25ec7bca | 164 | #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */ |