]>
Commit | Line | Data |
---|---|---|
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 KN |
6 | #include "refs.h" |
7 | #include "commit.h" | |
49abcd21 | 8 | #include "string-list.h" |
8255dd8a | 9 | #include "strvec.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 | 27 | struct atom_value; |
98e7ab6d | 28 | struct ref_sorting; |
49abcd21 | 29 | struct ahead_behind_count; |
c4d9c793 | 30 | struct option; |
69b1cf91 | 31 | |
98e7ab6d JH |
32 | enum 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 | ||
39 | struct 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 | ||
52 | struct 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 | ||
61 | struct 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; | |
69b1cf91 KN |
78 | }; |
79 | ||
4a68e36d JK |
80 | struct ref_format { |
81 | /* | |
82 | * Set these to define the format; make sure you call | |
83 | * verify_ref_format() afterwards to finalize. | |
84 | */ | |
85 | const char *format; | |
b9dee075 | 86 | const char *rest; |
4a68e36d | 87 | int quote_style; |
11b087ad | 88 | int use_color; |
bf285ae6 JK |
89 | |
90 | /* Internal state to ref-filter */ | |
91 | int need_color_reset_at_eol; | |
49abcd21 DS |
92 | |
93 | /* List of bases for ahead-behind counts. */ | |
94 | struct string_list bases; | |
4a68e36d JK |
95 | }; |
96 | ||
b9f7daa6 JK |
97 | #define REF_FILTER_INIT { \ |
98 | .points_at = OID_ARRAY_INIT, \ | |
8255dd8a | 99 | .exclude = STRVEC_INIT, \ |
b9f7daa6 | 100 | } |
49abcd21 DS |
101 | #define REF_FORMAT_INIT { \ |
102 | .use_color = -1, \ | |
103 | .bases = STRING_LIST_INIT_DUP, \ | |
104 | } | |
4a68e36d | 105 | |
5afcb905 KN |
106 | /* Macros for checking --merged and --no-merged options */ |
107 | #define _OPT_MERGED_NO_MERGED(option, filter, h) \ | |
108 | { OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \ | |
109 | PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \ | |
110 | parse_opt_merge_filter, (intptr_t) "HEAD" \ | |
111 | } | |
112 | #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h) | |
113 | #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h) | |
114 | ||
95be717c | 115 | #define OPT_REF_SORT(var) \ |
98e7ab6d JH |
116 | OPT_STRING_LIST(0, "sort", (var), \ |
117 | N_("key"), N_("field name to sort on")) | |
8255dd8a TB |
118 | #define OPT_REF_FILTER_EXCLUDE(var) \ |
119 | OPT_STRVEC(0, "exclude", &(var)->exclude, \ | |
120 | N_("pattern"), N_("exclude refs which match pattern")) | |
95be717c | 121 | |
14de7fba KN |
122 | /* |
123 | * API for filtering a set of refs. Based on the type of refs the user | |
124 | * has requested, we iterate through those refs and apply filters | |
125 | * as per the given ref_filter structure and finally store the | |
126 | * filtered refs in the ref_array structure. | |
127 | */ | |
128 | int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type); | |
69b1cf91 KN |
129 | /* Clear all memory allocated to ref_array */ |
130 | void ref_array_clear(struct ref_array *array); | |
69b1cf91 | 131 | /* Used to verify if the given format is correct and to parse out the used atoms */ |
4a68e36d | 132 | int verify_ref_format(struct ref_format *format); |
69b1cf91 KN |
133 | /* Sort the given ref_array as per the ref_sorting provided */ |
134 | void ref_array_sort(struct ref_sorting *sort, struct ref_array *array); | |
7c269a7b ÆAB |
135 | /* Set REF_SORTING_* sort_flags for all elements of a sorting list */ |
136 | void ref_sorting_set_sort_flags_all(struct ref_sorting *sorting, unsigned int mask, int on); | |
99c6a71d | 137 | /* Based on the given format and quote_style, fill the strbuf */ |
3019eca9 | 138 | int format_ref_array_item(struct ref_array_item *info, |
e85fcb35 | 139 | struct ref_format *format, |
3019eca9 OT |
140 | struct strbuf *final_buf, |
141 | struct strbuf *error_buf); | |
e5fb0286 ÆAB |
142 | /* Release a "struct ref_sorting" */ |
143 | void ref_sorting_release(struct ref_sorting *); | |
98e7ab6d JH |
144 | /* Convert list of sort options into ref_sorting */ |
145 | struct ref_sorting *ref_sorting_options(struct string_list *); | |
5afcb905 KN |
146 | /* Function to parse --merged and --no-merged options */ |
147 | int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset); | |
d4919bb2 KN |
148 | /* Get the current HEAD's description */ |
149 | char *get_head_description(void); | |
6eac70fa KN |
150 | /* Set up translated strings in the output. */ |
151 | void setup_ref_filter_porcelain_msg(void); | |
69b1cf91 | 152 | |
2111aa79 LP |
153 | /* |
154 | * Print a single ref, outside of any ref-filter. Note that the | |
155 | * name must be a fully qualified refname. | |
156 | */ | |
53df97a2 | 157 | void pretty_print_ref(const char *name, const struct object_id *oid, |
e85fcb35 | 158 | struct ref_format *format); |
2111aa79 | 159 | |
427cbc9d JK |
160 | /* |
161 | * Push a single ref onto the array; this can be used to construct your own | |
162 | * ref_array without using filter_refs(). | |
163 | */ | |
164 | struct ref_array_item *ref_array_push(struct ref_array *array, | |
165 | const char *refname, | |
166 | const struct object_id *oid); | |
167 | ||
49abcd21 DS |
168 | /* |
169 | * If the provided format includes ahead-behind atoms, then compute the | |
170 | * ahead-behind values for the array of filtered references. Must be | |
171 | * called after filter_refs() but before outputting the formatted refs. | |
172 | * | |
173 | * If this is not called, then any ahead-behind atoms will be blank. | |
174 | */ | |
175 | void filter_ahead_behind(struct repository *r, | |
176 | struct ref_format *format, | |
177 | struct ref_array *array); | |
178 | ||
b571fb98 JK |
179 | void ref_filter_init(struct ref_filter *filter); |
180 | void ref_filter_clear(struct ref_filter *filter); | |
181 | ||
69b1cf91 | 182 | #endif /* REF_FILTER_H */ |