Merge branch 'rs/alias-use-copy-array'
[git/git.git] / list-objects-filter-options.h
CommitLineData
25ec7bca
JH
1#ifndef LIST_OBJECTS_FILTER_OPTIONS_H
2#define LIST_OBJECTS_FILTER_OPTIONS_H
3
4#include "parse-options.h"
cf9ceb5a 5#include "string-list.h"
25ec7bca
JH
6
7/*
8 * The list of defined filters for list-objects.
9 */
10enum list_objects_filter_choice {
11 LOFC_DISABLED = 0,
12 LOFC_BLOB_NONE,
13 LOFC_BLOB_LIMIT,
c813a7c3 14 LOFC_TREE_DEPTH,
25ec7bca 15 LOFC_SPARSE_OID,
e987df5f 16 LOFC_COMBINE,
25ec7bca
JH
17 LOFC__COUNT /* must be last */
18};
19
20struct list_objects_filter_options {
21 /*
22 * 'filter_spec' is the raw argument value given on the command line
23 * or protocol request. (The part after the "--keyword=".) For
87c2d9d3
JS
24 * commands that launch filtering sub-processes, or for communication
25 * over the network, don't use this value; use the result of
26 * expand_list_objects_filter_spec() instead.
cf9ceb5a
MD
27 * To get the raw filter spec given by the user, use the result of
28 * list_objects_filter_spec().
25ec7bca 29 */
cf9ceb5a 30 struct string_list filter_spec;
25ec7bca
JH
31
32 /*
33 * 'choice' is determined by parsing the filter-spec. This indicates
34 * the filtering algorithm to use.
35 */
36 enum list_objects_filter_choice choice;
37
aa57b871
JH
38 /*
39 * Choice is LOFC_DISABLED because "--no-filter" was requested.
40 */
41 unsigned int no_filter : 1;
42
25ec7bca 43 /*
e987df5f
MD
44 * BEGIN choice-specific parsed values from within the filter-spec. Only
45 * some values will be defined for any given choice.
25ec7bca 46 */
e987df5f 47
4c96a775 48 char *sparse_oid_name;
25ec7bca 49 unsigned long blob_limit_value;
c813a7c3 50 unsigned long tree_exclude_depth;
e987df5f
MD
51
52 /* LOFC_COMBINE values */
53
54 /* This array contains all the subfilters which this filter combines. */
55 size_t sub_nr, sub_alloc;
56 struct list_objects_filter_options *sub;
57
58 /*
59 * END choice-specific parsed values.
60 */
25ec7bca
JH
61};
62
63/* Normalized command line arguments */
64#define CL_ARG__FILTER "filter"
65
489fc9ee
MD
66void list_objects_filter_die_if_populated(
67 struct list_objects_filter_options *filter_options);
68
69/*
70 * Parses the filter spec string given by arg and either (1) simply places the
71 * result in filter_options if it is not yet populated or (2) combines it with
72 * the filter already in filter_options if it is already populated. In the case
73 * of (2), the filter specs are combined as if specified with 'combine:'.
74 *
75 * Dies and prints a user-facing message if an error occurs.
76 */
90d21f9e 77void parse_list_objects_filter(
25ec7bca
JH
78 struct list_objects_filter_options *filter_options,
79 const char *arg);
80
81int opt_parse_list_objects_filter(const struct option *opt,
82 const char *arg, int unset);
83
84#define OPT_PARSE_LIST_OBJECTS_FILTER(fo) \
85 { OPTION_CALLBACK, 0, CL_ARG__FILTER, fo, N_("args"), \
4875c979 86 N_("object filtering"), 0, \
25ec7bca
JH
87 opt_parse_list_objects_filter }
88
87c2d9d3
JS
89/*
90 * Translates abbreviated numbers in the filter's filter_spec into their
91 * fully-expanded forms (e.g., "limit:blob=1k" becomes "limit:blob=1024").
cf9ceb5a 92 * Returns a string owned by the list_objects_filter_options object.
87c2d9d3 93 *
cf9ceb5a
MD
94 * This form should be used instead of the raw list_objects_filter_spec()
95 * value when communicating with a remote process or subprocess.
87c2d9d3 96 */
cf9ceb5a
MD
97const char *expand_list_objects_filter_spec(
98 struct list_objects_filter_options *filter);
99
100/*
101 * Returns the filter spec string more or less in the form as the user
102 * entered it. This form of the filter_spec can be used in user-facing
103 * messages. Returns a string owned by the list_objects_filter_options
104 * object.
105 */
106const char *list_objects_filter_spec(
107 struct list_objects_filter_options *filter);
87c2d9d3 108
4875c979
JH
109void list_objects_filter_release(
110 struct list_objects_filter_options *filter_options);
111
aa57b871
JH
112static inline void list_objects_filter_set_no_filter(
113 struct list_objects_filter_options *filter_options)
114{
115 list_objects_filter_release(filter_options);
116 filter_options->no_filter = 1;
117}
118
1e1e39b3
JH
119void partial_clone_register(
120 const char *remote,
cf9ceb5a 121 struct list_objects_filter_options *filter_options);
1e1e39b3 122void partial_clone_get_default_filter_spec(
fa3d1b63
CC
123 struct list_objects_filter_options *filter_options,
124 const char *remote);
1e1e39b3 125
25ec7bca 126#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */