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