7 #include "string-list.h"
9 #include "commit-reach.h"
15 #define QUOTE_PYTHON 4
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_REGULAR (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \
23 FILTER_REFS_REMOTES | FILTER_REFS_OTHERS)
24 #define FILTER_REFS_DETACHED_HEAD 0x0020
25 #define FILTER_REFS_PSEUDOREFS 0x0040
26 #define FILTER_REFS_ROOT_REFS 0x0080
27 #define FILTER_REFS_KIND_MASK (FILTER_REFS_REGULAR | FILTER_REFS_DETACHED_HEAD | \
28 FILTER_REFS_PSEUDOREFS | FILTER_REFS_ROOT_REFS)
32 struct ahead_behind_count
;
35 enum 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,
42 struct ref_array_item
{
43 struct object_id objectname
;
48 struct commit
*commit
;
49 struct atom_value
*value
;
50 struct ahead_behind_count
**counts
;
53 char refname
[FLEX_ARRAY
];
58 struct ref_array_item
**items
;
59 struct rev_info
*revs
;
61 struct ahead_behind_count
*counts
;
66 const char **name_patterns
;
67 struct strvec exclude
;
68 struct oid_array points_at
;
69 struct commit_list
*with_commit
;
70 struct commit_list
*no_commit
;
71 struct commit_list
*reachable_from
;
72 struct commit_list
*unreachable_from
;
74 unsigned int with_commit_tag_algo
: 1,
84 struct contains_cache contains_cache
;
85 struct contains_cache no_contains_cache
;
91 * Set these to define the format; make sure you call
92 * verify_ref_format() afterwards to finalize.
99 /* Internal state to ref-filter */
100 int need_color_reset_at_eol
;
108 #define REF_FILTER_INIT { \
109 .points_at = OID_ARRAY_INIT, \
110 .exclude = STRVEC_INIT, \
112 #define REF_FORMAT_INIT { \
116 /* Macros for checking --merged and --no-merged options */
117 #define _OPT_MERGED_NO_MERGED(option, filter, h) { \
118 .type = OPTION_CALLBACK, \
119 .long_name = option, \
121 .argh = N_("commit"), \
123 .flags = PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
124 .callback = parse_opt_merge_filter, \
125 .defval = (intptr_t) "HEAD", \
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)
130 #define OPT_REF_SORT(var) \
131 OPT_STRING_LIST(0, "sort", (var), \
132 N_("key"), N_("field name to sort on"))
133 #define OPT_REF_FILTER_EXCLUDE(var) \
134 OPT_STRVEC(0, "exclude", &(var)->exclude, \
135 N_("pattern"), N_("exclude refs which match pattern"))
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.
143 int filter_refs(struct ref_array
*array
, struct ref_filter
*filter
, unsigned int type
);
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.
149 void filter_and_format_refs(struct ref_filter
*filter
, unsigned int type
,
150 struct ref_sorting
*sorting
,
151 struct ref_format
*format
);
152 /* Clear all memory allocated to ref_array */
153 void ref_array_clear(struct ref_array
*array
);
154 /* Used to verify if the given format is correct and to parse out the used atoms */
155 int verify_ref_format(struct ref_format
*format
);
156 /* Sort the given ref_array as per the ref_sorting provided */
157 void ref_array_sort(struct ref_sorting
*sort
, struct ref_array
*array
);
158 /* Set REF_SORTING_* sort_flags for all elements of a sorting list */
159 void ref_sorting_set_sort_flags_all(struct ref_sorting
*sorting
, unsigned int mask
, int on
);
160 /* Based on the given format and quote_style, fill the strbuf */
161 int format_ref_array_item(struct ref_array_item
*info
,
162 struct ref_format
*format
,
163 struct strbuf
*final_buf
,
164 struct strbuf
*error_buf
);
165 /* Release a "struct ref_sorting" */
166 void ref_sorting_release(struct ref_sorting
*);
167 /* Convert list of sort options into ref_sorting */
168 struct ref_sorting
*ref_sorting_options(struct string_list
*);
169 /* Function to parse --merged and --no-merged options */
170 int parse_opt_merge_filter(const struct option
*opt
, const char *arg
, int unset
);
171 /* Get the current HEAD's description */
172 char *get_head_description(void);
173 /* Set up translated strings in the output. */
174 void setup_ref_filter_porcelain_msg(void);
177 * Print up to maxcount ref_array elements to stdout using the given
180 void print_formatted_ref_array(struct ref_array
*array
, struct ref_format
*format
);
183 * Print a single ref, outside of any ref-filter. Note that the
184 * name must be a fully qualified refname.
186 void pretty_print_ref(const char *name
, const struct object_id
*oid
,
187 struct ref_format
*format
);
190 * Push a single ref onto the array; this can be used to construct your own
191 * ref_array without using filter_refs().
193 struct ref_array_item
*ref_array_push(struct ref_array
*array
,
195 const struct object_id
*oid
);
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.
202 * If this is not called, then any ahead-behind atoms will be blank.
204 void filter_ahead_behind(struct repository
*r
,
205 struct ref_array
*array
);
208 * If the provided format includes is-base atoms, then compute the base checks
209 * for those tips against all refs.
211 * If this is not called, then any is-base atoms will be blank.
213 void filter_is_base(struct repository
*r
,
214 struct ref_array
*array
);
216 void ref_filter_init(struct ref_filter
*filter
);
217 void ref_filter_clear(struct ref_filter
*filter
);
219 #endif /* REF_FILTER_H */