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