blob: da5b6737e27e36a6e198a59a070cd30f17179ceb [file] [log] [blame]
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +00001#ifndef LIST_OBJECTS_FILTER_OPTIONS_H
2#define LIST_OBJECTS_FILTER_OPTIONS_H
3
Patrick Steinhardtb0c42a52021-04-19 13:46:53 +02004#include "cache.h"
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +00005#include "parse-options.h"
Matthew DeVorecf9ceb52019-06-27 15:54:10 -07006#include "string-list.h"
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +00007
8/*
9 * The list of defined filters for list-objects.
10 */
11enum list_objects_filter_choice {
12 LOFC_DISABLED = 0,
13 LOFC_BLOB_NONE,
14 LOFC_BLOB_LIMIT,
Matthew DeVorec813a7c2019-01-08 18:59:13 -080015 LOFC_TREE_DEPTH,
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000016 LOFC_SPARSE_OID,
Patrick Steinhardtb0c42a52021-04-19 13:46:53 +020017 LOFC_OBJECT_TYPE,
Matthew DeVoree987df52019-06-27 15:54:08 -070018 LOFC_COMBINE,
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000019 LOFC__COUNT /* must be last */
20};
21
Taylor Blaub9ea2142020-07-31 16:26:26 -040022/*
23 * Returns a configuration key suitable for describing the given object filter,
24 * e.g.: "blob:none", "combine", etc.
25 */
26const char *list_object_filter_config_name(enum list_objects_filter_choice c);
27
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000028struct 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 Steadmon87c2d9d2019-01-07 16:17:09 -080032 * 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 DeVorecf9ceb52019-06-27 15:54:10 -070035 * To get the raw filter spec given by the user, use the result of
36 * list_objects_filter_spec().
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000037 */
Matthew DeVorecf9ceb52019-06-27 15:54:10 -070038 struct string_list filter_spec;
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000039
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 Hostetleraa57b872017-12-08 15:58:50 +000047 * Choice is LOFC_DISABLED because "--no-filter" was requested.
48 */
49 unsigned int no_filter : 1;
50
51 /*
Matthew DeVoree987df52019-06-27 15:54:08 -070052 * BEGIN choice-specific parsed values from within the filter-spec. Only
53 * some values will be defined for any given choice.
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000054 */
Matthew DeVoree987df52019-06-27 15:54:08 -070055
Jeff King4c96a772019-09-15 12:12:44 -040056 char *sparse_oid_name;
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000057 unsigned long blob_limit_value;
Matthew DeVorec813a7c2019-01-08 18:59:13 -080058 unsigned long tree_exclude_depth;
Patrick Steinhardtb0c42a52021-04-19 13:46:53 +020059 enum object_type object_type;
Matthew DeVoree987df52019-06-27 15:54:08 -070060
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 Hostetler25ec7bc2017-11-21 20:58:50 +000070};
71
72/* Normalized command line arguments */
73#define CL_ARG__FILTER "filter"
74
Matthew DeVore489fc9e2019-06-27 15:54:12 -070075void list_objects_filter_die_if_populated(
76 struct list_objects_filter_options *filter_options);
77
78/*
79 * Parses the filter spec string given by arg and either (1) simply places the
80 * result in filter_options if it is not yet populated or (2) combines it with
81 * the filter already in filter_options if it is already populated. In the case
82 * of (2), the filter specs are combined as if specified with 'combine:'.
83 *
84 * Dies and prints a user-facing message if an error occurs.
85 */
Matthew DeVore90d21f92019-06-27 15:54:14 -070086void parse_list_objects_filter(
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000087 struct list_objects_filter_options *filter_options,
88 const char *arg);
89
90int opt_parse_list_objects_filter(const struct option *opt,
91 const char *arg, int unset);
92
93#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
Denton Liu203c8532020-04-28 04:36:28 -040094 OPT_CALLBACK(0, CL_ARG__FILTER, fo, N_("args"), \
95 N_("object filtering"), \
96 opt_parse_list_objects_filter)
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000097
Josh Steadmon87c2d9d2019-01-07 16:17:09 -080098/*
99 * Translates abbreviated numbers in the filter's filter_spec into their
100 * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024").
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700101 * Returns a string owned by the list_objects_filter_options object.
Josh Steadmon87c2d9d2019-01-07 16:17:09 -0800102 *
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700103 * This form should be used instead of the raw list_objects_filter_spec()
104 * value when communicating with a remote process or subprocess.
Josh Steadmon87c2d9d2019-01-07 16:17:09 -0800105 */
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700106const char *expand_list_objects_filter_spec(
107 struct list_objects_filter_options *filter);
108
109/*
110 * Returns the filter spec string more or less in the form as the user
111 * entered it. This form of the filter_spec can be used in user-facing
112 * messages. Returns a string owned by the list_objects_filter_options
113 * object.
114 */
115const char *list_objects_filter_spec(
116 struct list_objects_filter_options *filter);
Josh Steadmon87c2d9d2019-01-07 16:17:09 -0800117
Jeff Hostetler4875c972017-12-05 16:50:13 +0000118void list_objects_filter_release(
119 struct list_objects_filter_options *filter_options);
120
Jeff Hostetleraa57b872017-12-08 15:58:50 +0000121static inline void list_objects_filter_set_no_filter(
122 struct list_objects_filter_options *filter_options)
123{
124 list_objects_filter_release(filter_options);
125 filter_options->no_filter = 1;
126}
127
Jeff Hostetler1e1e39b2017-12-08 15:58:45 +0000128void partial_clone_register(
129 const char *remote,
Matthew DeVorecf9ceb52019-06-27 15:54:10 -0700130 struct list_objects_filter_options *filter_options);
Jeff Hostetler1e1e39b2017-12-08 15:58:45 +0000131void partial_clone_get_default_filter_spec(
Christian Couderfa3d1b62019-06-25 15:40:32 +0200132 struct list_objects_filter_options *filter_options,
133 const char *remote);
Jeff Hostetler1e1e39b2017-12-08 15:58:45 +0000134
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000135#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */