| 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 "strbuf.h" |
| 7 | |
| 8 | struct option; |
| 9 | |
| 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, |
| 17 | LOFC_TREE_DEPTH, |
| 18 | LOFC_SPARSE_OID, |
| 19 | LOFC_OBJECT_TYPE, |
| 20 | LOFC_COMBINE, |
| 21 | LOFC_AUTO, |
| 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 | * Is LOFC_AUTO a valid option? |
| 56 | */ |
| 57 | unsigned int allow_auto_filter : 1; |
| 58 | |
| 59 | /* |
| 60 | * BEGIN choice-specific parsed values from within the filter-spec. Only |
| 61 | * some values will be defined for any given choice. |
| 62 | */ |
| 63 | |
| 64 | char *sparse_oid_name; |
| 65 | unsigned long blob_limit_value; |
| 66 | unsigned long tree_exclude_depth; |
| 67 | enum object_type object_type; |
| 68 | |
| 69 | /* LOFC_COMBINE values */ |
| 70 | |
| 71 | /* This array contains all the subfilters which this filter combines. */ |
| 72 | size_t sub_nr, sub_alloc; |
| 73 | struct list_objects_filter_options *sub; |
| 74 | |
| 75 | /* |
| 76 | * END choice-specific parsed values. |
| 77 | */ |
| 78 | }; |
| 79 | |
| 80 | #define LIST_OBJECTS_FILTER_INIT { .filter_spec = STRBUF_INIT } |
| 81 | void list_objects_filter_init(struct list_objects_filter_options *filter_options); |
| 82 | |
| 83 | /* |
| 84 | * Parse value of the argument to the "filter" keyword. |
| 85 | * On the command line this looks like: |
| 86 | * --filter=<arg> |
| 87 | * and in the pack protocol as: |
| 88 | * "filter" SP <arg> |
| 89 | * |
| 90 | * The filter keyword will be used by many commands. |
| 91 | * See Documentation/rev-list-options.adoc for allowed values for <arg>. |
| 92 | * |
| 93 | * Capture the given arg as the "filter_spec". This can be forwarded to |
| 94 | * subordinate commands when necessary (although it's better to pass it through |
| 95 | * expand_list_objects_filter_spec() first). We also "intern" the arg for the |
| 96 | * convenience of the current command. |
| 97 | */ |
| 98 | int gently_parse_list_objects_filter( |
| 99 | struct list_objects_filter_options *filter_options, |
| 100 | const char *arg, |
| 101 | struct strbuf *errbuf); |
| 102 | |
| 103 | void list_objects_filter_die_if_populated( |
| 104 | struct list_objects_filter_options *filter_options); |
| 105 | |
| 106 | /* |
| 107 | * Parses the filter spec string given by arg and either (1) simply places the |
| 108 | * result in filter_options if it is not yet populated or (2) combines it with |
| 109 | * the filter already in filter_options if it is already populated. In the case |
| 110 | * of (2), the filter specs are combined as if specified with 'combine:'. |
| 111 | * |
| 112 | * Dies and prints a user-facing message if an error occurs. |
| 113 | */ |
| 114 | void parse_list_objects_filter( |
| 115 | struct list_objects_filter_options *filter_options, |
| 116 | const char *arg); |
| 117 | |
| 118 | /** |
| 119 | * The opt->value to opt_parse_list_objects_filter() is either a |
| 120 | * "struct list_objects_filter_option *" when using |
| 121 | * OPT_PARSE_LIST_OBJECTS_FILTER(). |
| 122 | */ |
| 123 | int opt_parse_list_objects_filter(const struct option *opt, |
| 124 | const char *arg, int unset); |
| 125 | |
| 126 | #define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \ |
| 127 | OPT_CALLBACK(0, "filter", (fo), N_("args"), \ |
| 128 | N_("object filtering"), opt_parse_list_objects_filter) |
| 129 | |
| 130 | /* |
| 131 | * Translates abbreviated numbers in the filter's filter_spec into their |
| 132 | * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024"). |
| 133 | * Returns a string owned by the list_objects_filter_options object. |
| 134 | * |
| 135 | * This form should be used instead of the raw list_objects_filter_spec() |
| 136 | * value when communicating with a remote process or subprocess. |
| 137 | */ |
| 138 | const char *expand_list_objects_filter_spec( |
| 139 | struct list_objects_filter_options *filter); |
| 140 | |
| 141 | /* |
| 142 | * Returns the filter spec string more or less in the form as the user |
| 143 | * entered it. This form of the filter_spec can be used in user-facing |
| 144 | * messages. Returns a string owned by the list_objects_filter_options |
| 145 | * object. |
| 146 | */ |
| 147 | const char *list_objects_filter_spec( |
| 148 | struct list_objects_filter_options *filter); |
| 149 | |
| 150 | void list_objects_filter_release( |
| 151 | struct list_objects_filter_options *filter_options); |
| 152 | |
| 153 | static inline void list_objects_filter_set_no_filter( |
| 154 | struct list_objects_filter_options *filter_options) |
| 155 | { |
| 156 | list_objects_filter_release(filter_options); |
| 157 | filter_options->no_filter = 1; |
| 158 | } |
| 159 | |
| 160 | void partial_clone_register( |
| 161 | const char *remote, |
| 162 | struct list_objects_filter_options *filter_options); |
| 163 | void partial_clone_get_default_filter_spec( |
| 164 | struct list_objects_filter_options *filter_options, |
| 165 | const char *remote); |
| 166 | |
| 167 | void list_objects_filter_copy( |
| 168 | struct list_objects_filter_options *dest, |
| 169 | const struct list_objects_filter_options *src); |
| 170 | |
| 171 | #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */ |