Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 1 | #ifndef LIST_OBJECTS_FILTER_OPTIONS_H |
| 2 | #define LIST_OBJECTS_FILTER_OPTIONS_H |
| 3 | |
Patrick Steinhardt | b0c42a5 | 2021-04-19 13:46:53 +0200 | [diff] [blame] | 4 | #include "cache.h" |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 5 | #include "parse-options.h" |
Matthew DeVore | cf9ceb5 | 2019-06-27 15:54:10 -0700 | [diff] [blame] | 6 | #include "string-list.h" |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 7 | |
| 8 | /* |
| 9 | * The list of defined filters for list-objects. |
| 10 | */ |
| 11 | enum list_objects_filter_choice { |
| 12 | LOFC_DISABLED = 0, |
| 13 | LOFC_BLOB_NONE, |
| 14 | LOFC_BLOB_LIMIT, |
Matthew DeVore | c813a7c | 2019-01-08 18:59:13 -0800 | [diff] [blame] | 15 | LOFC_TREE_DEPTH, |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 16 | LOFC_SPARSE_OID, |
Patrick Steinhardt | b0c42a5 | 2021-04-19 13:46:53 +0200 | [diff] [blame] | 17 | LOFC_OBJECT_TYPE, |
Matthew DeVore | e987df5 | 2019-06-27 15:54:08 -0700 | [diff] [blame] | 18 | LOFC_COMBINE, |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 19 | LOFC__COUNT /* must be last */ |
| 20 | }; |
| 21 | |
Taylor Blau | b9ea214 | 2020-07-31 16:26:26 -0400 | [diff] [blame] | 22 | /* |
| 23 | * Returns a configuration key suitable for describing the given object filter, |
| 24 | * e.g.: "blob:none", "combine", etc. |
| 25 | */ |
| 26 | const char *list_object_filter_config_name(enum list_objects_filter_choice c); |
| 27 | |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 28 | struct list_objects_filter_options { |
| 29 | /* |
| 30 | * 'filter_spec' is the raw argument value given on the command line |
| 31 | * or protocol request. (The part after the "--keyword=".) For |
Josh Steadmon | 87c2d9d | 2019-01-07 16:17:09 -0800 | [diff] [blame] | 32 | * commands that launch filtering sub-processes, or for communication |
| 33 | * over the network, don't use this value; use the result of |
| 34 | * expand_list_objects_filter_spec() instead. |
Matthew DeVore | cf9ceb5 | 2019-06-27 15:54:10 -0700 | [diff] [blame] | 35 | * To get the raw filter spec given by the user, use the result of |
| 36 | * list_objects_filter_spec(). |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 37 | */ |
Matthew DeVore | cf9ceb5 | 2019-06-27 15:54:10 -0700 | [diff] [blame] | 38 | struct string_list filter_spec; |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * 'choice' is determined by parsing the filter-spec. This indicates |
| 42 | * the filtering algorithm to use. |
| 43 | */ |
| 44 | enum list_objects_filter_choice choice; |
| 45 | |
| 46 | /* |
Jeff Hostetler | aa57b87 | 2017-12-08 15:58:50 +0000 | [diff] [blame] | 47 | * Choice is LOFC_DISABLED because "--no-filter" was requested. |
| 48 | */ |
| 49 | unsigned int no_filter : 1; |
| 50 | |
| 51 | /* |
Matthew DeVore | e987df5 | 2019-06-27 15:54:08 -0700 | [diff] [blame] | 52 | * BEGIN choice-specific parsed values from within the filter-spec. Only |
| 53 | * some values will be defined for any given choice. |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 54 | */ |
Matthew DeVore | e987df5 | 2019-06-27 15:54:08 -0700 | [diff] [blame] | 55 | |
Jeff King | 4c96a77 | 2019-09-15 12:12:44 -0400 | [diff] [blame] | 56 | char *sparse_oid_name; |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 57 | unsigned long blob_limit_value; |
Matthew DeVore | c813a7c | 2019-01-08 18:59:13 -0800 | [diff] [blame] | 58 | unsigned long tree_exclude_depth; |
Patrick Steinhardt | b0c42a5 | 2021-04-19 13:46:53 +0200 | [diff] [blame] | 59 | enum object_type object_type; |
Matthew DeVore | e987df5 | 2019-06-27 15:54:08 -0700 | [diff] [blame] | 60 | |
| 61 | /* LOFC_COMBINE values */ |
| 62 | |
| 63 | /* This array contains all the subfilters which this filter combines. */ |
| 64 | size_t sub_nr, sub_alloc; |
| 65 | struct list_objects_filter_options *sub; |
| 66 | |
| 67 | /* |
| 68 | * END choice-specific parsed values. |
| 69 | */ |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Derrick Stolee | 105c6f1 | 2022-03-09 16:01:39 +0000 | [diff] [blame] | 72 | /* |
| 73 | * Parse value of the argument to the "filter" keyword. |
| 74 | * On the command line this looks like: |
| 75 | * --filter=<arg> |
| 76 | * and in the pack protocol as: |
| 77 | * "filter" SP <arg> |
| 78 | * |
| 79 | * The filter keyword will be used by many commands. |
| 80 | * See Documentation/rev-list-options.txt for allowed values for <arg>. |
| 81 | * |
| 82 | * Capture the given arg as the "filter_spec". This can be forwarded to |
| 83 | * subordinate commands when necessary (although it's better to pass it through |
| 84 | * expand_list_objects_filter_spec() first). We also "intern" the arg for the |
| 85 | * convenience of the current command. |
| 86 | */ |
| 87 | int gently_parse_list_objects_filter( |
| 88 | struct list_objects_filter_options *filter_options, |
| 89 | const char *arg, |
| 90 | struct strbuf *errbuf); |
| 91 | |
Matthew DeVore | 489fc9e | 2019-06-27 15:54:12 -0700 | [diff] [blame] | 92 | void list_objects_filter_die_if_populated( |
| 93 | struct list_objects_filter_options *filter_options); |
| 94 | |
| 95 | /* |
| 96 | * Parses the filter spec string given by arg and either (1) simply places the |
| 97 | * result in filter_options if it is not yet populated or (2) combines it with |
| 98 | * the filter already in filter_options if it is already populated. In the case |
| 99 | * of (2), the filter specs are combined as if specified with 'combine:'. |
| 100 | * |
| 101 | * Dies and prints a user-facing message if an error occurs. |
| 102 | */ |
Matthew DeVore | 90d21f9 | 2019-06-27 15:54:14 -0700 | [diff] [blame] | 103 | void parse_list_objects_filter( |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 104 | struct list_objects_filter_options *filter_options, |
| 105 | const char *arg); |
| 106 | |
Ævar Arnfjörð Bjarmason | 5cb2827 | 2022-03-28 17:43:18 +0200 | [diff] [blame] | 107 | /** |
| 108 | * The opt->value to opt_parse_list_objects_filter() is either a |
| 109 | * "struct list_objects_filter_option *" when using |
| 110 | * OPT_PARSE_LIST_OBJECTS_FILTER(). |
| 111 | * |
| 112 | * Or, if using no "struct option" field is used by the callback, |
| 113 | * except the "defval" which is expected to be an "opt_lof_init" |
| 114 | * function, which is called with the "opt->value" and must return a |
| 115 | * pointer to the ""struct list_objects_filter_option *" to be used. |
| 116 | * |
| 117 | * The OPT_PARSE_LIST_OBJECTS_FILTER_INIT() can be used e.g. the |
| 118 | * "struct list_objects_filter_option" is embedded in a "struct |
| 119 | * rev_info", which the "defval" could be tasked with lazily |
| 120 | * initializing. See cmd_pack_objects() for an example. |
| 121 | */ |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 122 | int opt_parse_list_objects_filter(const struct option *opt, |
| 123 | const char *arg, int unset); |
Ævar Arnfjörð Bjarmason | 5cb2827 | 2022-03-28 17:43:18 +0200 | [diff] [blame] | 124 | typedef struct list_objects_filter_options *(*opt_lof_init)(void *); |
| 125 | #define OPT_PARSE_LIST_OBJECTS_FILTER_INIT(fo, init) \ |
| 126 | { OPTION_CALLBACK, 0, "filter", (fo), N_("args"), \ |
| 127 | N_("object filtering"), 0, opt_parse_list_objects_filter, \ |
| 128 | (intptr_t)(init) } |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 129 | |
| 130 | #define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \ |
Ævar Arnfjörð Bjarmason | 5cb2827 | 2022-03-28 17:43:18 +0200 | [diff] [blame] | 131 | OPT_PARSE_LIST_OBJECTS_FILTER_INIT((fo), NULL) |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 132 | |
Josh Steadmon | 87c2d9d | 2019-01-07 16:17:09 -0800 | [diff] [blame] | 133 | /* |
| 134 | * Translates abbreviated numbers in the filter's filter_spec into their |
| 135 | * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024"). |
Matthew DeVore | cf9ceb5 | 2019-06-27 15:54:10 -0700 | [diff] [blame] | 136 | * Returns a string owned by the list_objects_filter_options object. |
Josh Steadmon | 87c2d9d | 2019-01-07 16:17:09 -0800 | [diff] [blame] | 137 | * |
Matthew DeVore | cf9ceb5 | 2019-06-27 15:54:10 -0700 | [diff] [blame] | 138 | * This form should be used instead of the raw list_objects_filter_spec() |
| 139 | * value when communicating with a remote process or subprocess. |
Josh Steadmon | 87c2d9d | 2019-01-07 16:17:09 -0800 | [diff] [blame] | 140 | */ |
Matthew DeVore | cf9ceb5 | 2019-06-27 15:54:10 -0700 | [diff] [blame] | 141 | const char *expand_list_objects_filter_spec( |
| 142 | struct list_objects_filter_options *filter); |
| 143 | |
| 144 | /* |
| 145 | * Returns the filter spec string more or less in the form as the user |
| 146 | * entered it. This form of the filter_spec can be used in user-facing |
| 147 | * messages. Returns a string owned by the list_objects_filter_options |
| 148 | * object. |
| 149 | */ |
| 150 | const char *list_objects_filter_spec( |
| 151 | struct list_objects_filter_options *filter); |
Josh Steadmon | 87c2d9d | 2019-01-07 16:17:09 -0800 | [diff] [blame] | 152 | |
Jeff Hostetler | 4875c97 | 2017-12-05 16:50:13 +0000 | [diff] [blame] | 153 | void list_objects_filter_release( |
| 154 | struct list_objects_filter_options *filter_options); |
| 155 | |
Jeff Hostetler | aa57b87 | 2017-12-08 15:58:50 +0000 | [diff] [blame] | 156 | static inline void list_objects_filter_set_no_filter( |
| 157 | struct list_objects_filter_options *filter_options) |
| 158 | { |
| 159 | list_objects_filter_release(filter_options); |
| 160 | filter_options->no_filter = 1; |
| 161 | } |
| 162 | |
Jeff Hostetler | 1e1e39b | 2017-12-08 15:58:45 +0000 | [diff] [blame] | 163 | void partial_clone_register( |
| 164 | const char *remote, |
Matthew DeVore | cf9ceb5 | 2019-06-27 15:54:10 -0700 | [diff] [blame] | 165 | struct list_objects_filter_options *filter_options); |
Jeff Hostetler | 1e1e39b | 2017-12-08 15:58:45 +0000 | [diff] [blame] | 166 | void partial_clone_get_default_filter_spec( |
Christian Couder | fa3d1b6 | 2019-06-25 15:40:32 +0200 | [diff] [blame] | 167 | struct list_objects_filter_options *filter_options, |
| 168 | const char *remote); |
Jeff Hostetler | 1e1e39b | 2017-12-08 15:58:45 +0000 | [diff] [blame] | 169 | |
Derrick Stolee | 4a4c3f9 | 2022-03-09 16:01:32 +0000 | [diff] [blame] | 170 | void list_objects_filter_copy( |
| 171 | struct list_objects_filter_options *dest, |
| 172 | const struct list_objects_filter_options *src); |
| 173 | |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 174 | #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */ |