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