8 #include "string-list.h"
10 #include "commit-reach.h"
16 #define QUOTE_PYTHON 4
19 #define FILTER_REFS_TAGS 0x0002
20 #define FILTER_REFS_BRANCHES 0x0004
21 #define FILTER_REFS_REMOTES 0x0008
22 #define FILTER_REFS_OTHERS 0x0010
23 #define FILTER_REFS_ALL (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \
24 FILTER_REFS_REMOTES | FILTER_REFS_OTHERS)
25 #define FILTER_REFS_DETACHED_HEAD 0x0020
26 #define FILTER_REFS_KIND_MASK (FILTER_REFS_ALL | FILTER_REFS_DETACHED_HEAD)
30 struct ahead_behind_count
;
33 enum ref_sorting_order
{
34 REF_SORTING_REVERSE
= 1<<0,
35 REF_SORTING_ICASE
= 1<<1,
36 REF_SORTING_VERSION
= 1<<2,
37 REF_SORTING_DETACHED_HEAD_FIRST
= 1<<3,
40 struct ref_array_item
{
41 struct object_id objectname
;
46 struct commit
*commit
;
47 struct atom_value
*value
;
48 struct ahead_behind_count
**counts
;
50 char refname
[FLEX_ARRAY
];
55 struct ref_array_item
**items
;
56 struct rev_info
*revs
;
58 struct ahead_behind_count
*counts
;
63 const char **name_patterns
;
64 struct strvec exclude
;
65 struct oid_array points_at
;
66 struct commit_list
*with_commit
;
67 struct commit_list
*no_commit
;
68 struct commit_list
*reachable_from
;
69 struct commit_list
*unreachable_from
;
71 unsigned int with_commit_tag_algo
: 1,
81 struct contains_cache contains_cache
;
82 struct contains_cache no_contains_cache
;
88 * Set these to define the format; make sure you call
89 * verify_ref_format() afterwards to finalize.
96 /* Internal state to ref-filter */
97 int need_color_reset_at_eol
;
99 /* List of bases for ahead-behind counts. */
100 struct string_list bases
;
108 #define REF_FILTER_INIT { \
109 .points_at = OID_ARRAY_INIT, \
110 .exclude = STRVEC_INIT, \
112 #define REF_FORMAT_INIT { \
114 .bases = STRING_LIST_INIT_DUP, \
117 /* Macros for checking --merged and --no-merged options */
118 #define _OPT_MERGED_NO_MERGED(option, filter, h) \
119 { OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
120 PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
121 parse_opt_merge_filter, (intptr_t) "HEAD" \
123 #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
124 #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
126 #define OPT_REF_SORT(var) \
127 OPT_STRING_LIST(0, "sort", (var), \
128 N_("key"), N_("field name to sort on"))
129 #define OPT_REF_FILTER_EXCLUDE(var) \
130 OPT_STRVEC(0, "exclude", &(var)->exclude, \
131 N_("pattern"), N_("exclude refs which match pattern"))
134 * API for filtering a set of refs. Based on the type of refs the user
135 * has requested, we iterate through those refs and apply filters
136 * as per the given ref_filter structure and finally store the
137 * filtered refs in the ref_array structure.
139 int filter_refs(struct ref_array
*array
, struct ref_filter
*filter
, unsigned int type
);
141 * Filter refs using the given ref_filter and type, sort the contents
142 * according to the given ref_sorting, format the filtered refs with the
143 * given ref_format, and print them to stdout.
145 void filter_and_format_refs(struct ref_filter
*filter
, unsigned int type
,
146 struct ref_sorting
*sorting
,
147 struct ref_format
*format
);
148 /* Clear all memory allocated to ref_array */
149 void ref_array_clear(struct ref_array
*array
);
150 /* Used to verify if the given format is correct and to parse out the used atoms */
151 int verify_ref_format(struct ref_format
*format
);
152 /* Sort the given ref_array as per the ref_sorting provided */
153 void ref_array_sort(struct ref_sorting
*sort
, struct ref_array
*array
);
154 /* Set REF_SORTING_* sort_flags for all elements of a sorting list */
155 void ref_sorting_set_sort_flags_all(struct ref_sorting
*sorting
, unsigned int mask
, int on
);
156 /* Based on the given format and quote_style, fill the strbuf */
157 int format_ref_array_item(struct ref_array_item
*info
,
158 struct ref_format
*format
,
159 struct strbuf
*final_buf
,
160 struct strbuf
*error_buf
);
161 /* Release a "struct ref_sorting" */
162 void ref_sorting_release(struct ref_sorting
*);
163 /* Convert list of sort options into ref_sorting */
164 struct ref_sorting
*ref_sorting_options(struct string_list
*);
165 /* Function to parse --merged and --no-merged options */
166 int parse_opt_merge_filter(const struct option
*opt
, const char *arg
, int unset
);
167 /* Get the current HEAD's description */
168 char *get_head_description(void);
169 /* Set up translated strings in the output. */
170 void setup_ref_filter_porcelain_msg(void);
173 * Print up to maxcount ref_array elements to stdout using the given
176 void print_formatted_ref_array(struct ref_array
*array
, struct ref_format
*format
);
179 * Print a single ref, outside of any ref-filter. Note that the
180 * name must be a fully qualified refname.
182 void pretty_print_ref(const char *name
, const struct object_id
*oid
,
183 struct ref_format
*format
);
186 * Push a single ref onto the array; this can be used to construct your own
187 * ref_array without using filter_refs().
189 struct ref_array_item
*ref_array_push(struct ref_array
*array
,
191 const struct object_id
*oid
);
194 * If the provided format includes ahead-behind atoms, then compute the
195 * ahead-behind values for the array of filtered references. Must be
196 * called after filter_refs() but before outputting the formatted refs.
198 * If this is not called, then any ahead-behind atoms will be blank.
200 void filter_ahead_behind(struct repository
*r
,
201 struct ref_format
*format
,
202 struct ref_array
*array
);
204 void ref_filter_init(struct ref_filter
*filter
);
205 void ref_filter_clear(struct ref_filter
*filter
);
207 #endif /* REF_FILTER_H */