]> git.ipfire.org Git - thirdparty/git.git/blame - ref-filter.h
The sixth batch
[thirdparty/git.git] / ref-filter.h
CommitLineData
69b1cf91
KN
1#ifndef REF_FILTER_H
2#define REF_FILTER_H
3
f394e093 4#include "gettext.h"
fe299ec5 5#include "oid-array.h"
69b1cf91 6#include "commit.h"
49abcd21 7#include "string-list.h"
8255dd8a 8#include "strvec.h"
6d6e5c53 9#include "commit-reach.h"
69b1cf91
KN
10
11/* Quoting styles */
12#define QUOTE_NONE 0
13#define QUOTE_SHELL 1
14#define QUOTE_PERL 2
15#define QUOTE_PYTHON 4
16#define QUOTE_TCL 8
17
5b4f2851
KN
18#define FILTER_REFS_TAGS 0x0002
19#define FILTER_REFS_BRANCHES 0x0004
20#define FILTER_REFS_REMOTES 0x0008
21#define FILTER_REFS_OTHERS 0x0010
810f7a1a 22#define FILTER_REFS_REGULAR (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \
5b4f2851
KN
23 FILTER_REFS_REMOTES | FILTER_REFS_OTHERS)
24#define FILTER_REFS_DETACHED_HEAD 0x0020
33d15b54 25#define FILTER_REFS_PSEUDOREFS 0x0040
f1701f27 26#define FILTER_REFS_ROOT_REFS 0x0080
33d15b54 27#define FILTER_REFS_KIND_MASK (FILTER_REFS_REGULAR | FILTER_REFS_DETACHED_HEAD | \
f1701f27 28 FILTER_REFS_PSEUDOREFS | FILTER_REFS_ROOT_REFS)
14de7fba 29
3a25761a 30struct atom_value;
98e7ab6d 31struct ref_sorting;
49abcd21 32struct ahead_behind_count;
c4d9c793 33struct option;
69b1cf91 34
98e7ab6d
JH
35enum ref_sorting_order {
36 REF_SORTING_REVERSE = 1<<0,
37 REF_SORTING_ICASE = 1<<1,
38 REF_SORTING_VERSION = 1<<2,
39 REF_SORTING_DETACHED_HEAD_FIRST = 1<<3,
69b1cf91
KN
40};
41
42struct ref_array_item {
cedfc41a 43 struct object_id objectname;
b9dee075 44 const char *rest;
69b1cf91 45 int flag;
5b4f2851 46 unsigned int kind;
69b1cf91 47 const char *symref;
35257aa0 48 struct commit *commit;
69b1cf91 49 struct atom_value *value;
49abcd21 50 struct ahead_behind_count **counts;
9c1732ca 51 char **is_base;
49abcd21 52
1958a6eb 53 char refname[FLEX_ARRAY];
69b1cf91
KN
54};
55
56struct ref_array {
57 int nr, alloc;
58 struct ref_array_item **items;
1511b22d 59 struct rev_info *revs;
49abcd21
DS
60
61 struct ahead_behind_count *counts;
62 size_t counts_nr;
69b1cf91
KN
63};
64
65struct ref_filter {
66 const char **name_patterns;
8255dd8a 67 struct strvec exclude;
910650d2 68 struct oid_array points_at;
ee2bd06b 69 struct commit_list *with_commit;
ac3f5a34 70 struct commit_list *no_commit;
21bf9339
AL
71 struct commit_list *reachable_from;
72 struct commit_list *unreachable_from;
ee2bd06b 73
bef0e12b 74 unsigned int with_commit_tag_algo : 1,
1511b22d 75 match_as_path : 1,
3bb16a8b 76 ignore_case : 1,
1511b22d 77 detached : 1;
1bb38e5a
KN
78 unsigned int kind,
79 lines;
1511b22d
KN
80 int abbrev,
81 verbose;
6d6e5c53
VD
82
83 struct {
84 struct contains_cache contains_cache;
85 struct contains_cache no_contains_cache;
86 } internal;
69b1cf91
KN
87};
88
4a68e36d
JK
89struct ref_format {
90 /*
91 * Set these to define the format; make sure you call
92 * verify_ref_format() afterwards to finalize.
93 */
94 const char *format;
b9dee075 95 const char *rest;
4a68e36d 96 int quote_style;
11b087ad 97 int use_color;
bf285ae6
JK
98
99 /* Internal state to ref-filter */
100 int need_color_reset_at_eol;
49abcd21 101
9d4fcfe1
VD
102 struct {
103 int max_count;
104 int omit_empty;
105 } array_opts;
4a68e36d
JK
106};
107
b9f7daa6
JK
108#define REF_FILTER_INIT { \
109 .points_at = OID_ARRAY_INIT, \
8255dd8a 110 .exclude = STRVEC_INIT, \
b9f7daa6 111}
49abcd21
DS
112#define REF_FORMAT_INIT { \
113 .use_color = -1, \
49abcd21 114}
4a68e36d 115
5afcb905 116/* Macros for checking --merged and --no-merged options */
d012ceb5
PS
117#define _OPT_MERGED_NO_MERGED(option, filter, h) { \
118 .type = OPTION_CALLBACK, \
119 .long_name = option, \
120 .value = (filter), \
121 .argh = N_("commit"), \
122 .help = (h), \
123 .flags = PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
124 .callback = parse_opt_merge_filter, \
125 .defval = (intptr_t) "HEAD", \
126}
5afcb905
KN
127#define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
128#define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
129
95be717c 130#define OPT_REF_SORT(var) \
98e7ab6d
JH
131 OPT_STRING_LIST(0, "sort", (var), \
132 N_("key"), N_("field name to sort on"))
8255dd8a
TB
133#define OPT_REF_FILTER_EXCLUDE(var) \
134 OPT_STRVEC(0, "exclude", &(var)->exclude, \
135 N_("pattern"), N_("exclude refs which match pattern"))
95be717c 136
14de7fba
KN
137/*
138 * API for filtering a set of refs. Based on the type of refs the user
139 * has requested, we iterate through those refs and apply filters
140 * as per the given ref_filter structure and finally store the
141 * filtered refs in the ref_array structure.
142 */
143int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type);
e7574b0c
VD
144/*
145 * Filter refs using the given ref_filter and type, sort the contents
146 * according to the given ref_sorting, format the filtered refs with the
147 * given ref_format, and print them to stdout.
148 */
149void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
150 struct ref_sorting *sorting,
151 struct ref_format *format);
69b1cf91
KN
152/* Clear all memory allocated to ref_array */
153void ref_array_clear(struct ref_array *array);
69b1cf91 154/* Used to verify if the given format is correct and to parse out the used atoms */
4a68e36d 155int verify_ref_format(struct ref_format *format);
69b1cf91
KN
156/* Sort the given ref_array as per the ref_sorting provided */
157void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
7c269a7b
ÆAB
158/* Set REF_SORTING_* sort_flags for all elements of a sorting list */
159void ref_sorting_set_sort_flags_all(struct ref_sorting *sorting, unsigned int mask, int on);
99c6a71d 160/* Based on the given format and quote_style, fill the strbuf */
3019eca9 161int format_ref_array_item(struct ref_array_item *info,
e85fcb35 162 struct ref_format *format,
3019eca9
OT
163 struct strbuf *final_buf,
164 struct strbuf *error_buf);
e5fb0286
ÆAB
165/* Release a "struct ref_sorting" */
166void ref_sorting_release(struct ref_sorting *);
98e7ab6d
JH
167/* Convert list of sort options into ref_sorting */
168struct ref_sorting *ref_sorting_options(struct string_list *);
5afcb905
KN
169/* Function to parse --merged and --no-merged options */
170int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
d4919bb2
KN
171/* Get the current HEAD's description */
172char *get_head_description(void);
6eac70fa
KN
173/* Set up translated strings in the output. */
174void setup_ref_filter_porcelain_msg(void);
69b1cf91 175
e7574b0c
VD
176/*
177 * Print up to maxcount ref_array elements to stdout using the given
178 * ref_format.
179 */
180void print_formatted_ref_array(struct ref_array *array, struct ref_format *format);
181
2111aa79
LP
182/*
183 * Print a single ref, outside of any ref-filter. Note that the
184 * name must be a fully qualified refname.
185 */
53df97a2 186void pretty_print_ref(const char *name, const struct object_id *oid,
e85fcb35 187 struct ref_format *format);
2111aa79 188
427cbc9d
JK
189/*
190 * Push a single ref onto the array; this can be used to construct your own
191 * ref_array without using filter_refs().
192 */
193struct ref_array_item *ref_array_push(struct ref_array *array,
194 const char *refname,
195 const struct object_id *oid);
196
49abcd21
DS
197/*
198 * If the provided format includes ahead-behind atoms, then compute the
199 * ahead-behind values for the array of filtered references. Must be
200 * called after filter_refs() but before outputting the formatted refs.
201 *
202 * If this is not called, then any ahead-behind atoms will be blank.
203 */
204void filter_ahead_behind(struct repository *r,
49abcd21
DS
205 struct ref_array *array);
206
9c1732ca
DS
207/*
208 * If the provided format includes is-base atoms, then compute the base checks
209 * for those tips against all refs.
210 *
211 * If this is not called, then any is-base atoms will be blank.
212 */
213void filter_is_base(struct repository *r,
9c1732ca
DS
214 struct ref_array *array);
215
b571fb98
JK
216void ref_filter_init(struct ref_filter *filter);
217void ref_filter_clear(struct ref_filter *filter);
218
69b1cf91 219#endif /* REF_FILTER_H */