8 #include "string-list.h"
14 #define QUOTE_PYTHON 4
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)
28 struct ahead_behind_count
;
31 enum 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,
38 struct ref_array_item
{
39 struct object_id objectname
;
44 struct commit
*commit
;
45 struct atom_value
*value
;
46 struct ahead_behind_count
**counts
;
48 char refname
[FLEX_ARRAY
];
53 struct ref_array_item
**items
;
54 struct rev_info
*revs
;
56 struct ahead_behind_count
*counts
;
61 const char **name_patterns
;
62 struct oid_array points_at
;
63 struct commit_list
*with_commit
;
64 struct commit_list
*no_commit
;
65 struct commit_list
*reachable_from
;
66 struct commit_list
*unreachable_from
;
68 unsigned int with_commit_tag_algo
: 1,
80 * Set these to define the format; make sure you call
81 * verify_ref_format() afterwards to finalize.
88 /* Internal state to ref-filter */
89 int need_color_reset_at_eol
;
91 /* List of bases for ahead-behind counts. */
92 struct string_list bases
;
95 #define REF_FILTER_INIT { \
96 .points_at = OID_ARRAY_INIT, \
98 #define REF_FORMAT_INIT { \
100 .bases = STRING_LIST_INIT_DUP, \
103 /* Macros for checking --merged and --no-merged options */
104 #define _OPT_MERGED_NO_MERGED(option, filter, h) \
105 { OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
106 PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
107 parse_opt_merge_filter, (intptr_t) "HEAD" \
109 #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
110 #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
112 #define OPT_REF_SORT(var) \
113 OPT_STRING_LIST(0, "sort", (var), \
114 N_("key"), N_("field name to sort on"))
117 * API for filtering a set of refs. Based on the type of refs the user
118 * has requested, we iterate through those refs and apply filters
119 * as per the given ref_filter structure and finally store the
120 * filtered refs in the ref_array structure.
122 int filter_refs(struct ref_array
*array
, struct ref_filter
*filter
, unsigned int type
);
123 /* Clear all memory allocated to ref_array */
124 void ref_array_clear(struct ref_array
*array
);
125 /* Used to verify if the given format is correct and to parse out the used atoms */
126 int verify_ref_format(struct ref_format
*format
);
127 /* Sort the given ref_array as per the ref_sorting provided */
128 void ref_array_sort(struct ref_sorting
*sort
, struct ref_array
*array
);
129 /* Set REF_SORTING_* sort_flags for all elements of a sorting list */
130 void ref_sorting_set_sort_flags_all(struct ref_sorting
*sorting
, unsigned int mask
, int on
);
131 /* Based on the given format and quote_style, fill the strbuf */
132 int format_ref_array_item(struct ref_array_item
*info
,
133 struct ref_format
*format
,
134 struct strbuf
*final_buf
,
135 struct strbuf
*error_buf
);
136 /* Release a "struct ref_sorting" */
137 void ref_sorting_release(struct ref_sorting
*);
138 /* Convert list of sort options into ref_sorting */
139 struct ref_sorting
*ref_sorting_options(struct string_list
*);
140 /* Function to parse --merged and --no-merged options */
141 int parse_opt_merge_filter(const struct option
*opt
, const char *arg
, int unset
);
142 /* Get the current HEAD's description */
143 char *get_head_description(void);
144 /* Set up translated strings in the output. */
145 void setup_ref_filter_porcelain_msg(void);
148 * Print a single ref, outside of any ref-filter. Note that the
149 * name must be a fully qualified refname.
151 void pretty_print_ref(const char *name
, const struct object_id
*oid
,
152 struct ref_format
*format
);
155 * Push a single ref onto the array; this can be used to construct your own
156 * ref_array without using filter_refs().
158 struct ref_array_item
*ref_array_push(struct ref_array
*array
,
160 const struct object_id
*oid
);
163 * If the provided format includes ahead-behind atoms, then compute the
164 * ahead-behind values for the array of filtered references. Must be
165 * called after filter_refs() but before outputting the formatted refs.
167 * If this is not called, then any ahead-behind atoms will be blank.
169 void filter_ahead_behind(struct repository
*r
,
170 struct ref_format
*format
,
171 struct ref_array
*array
);
173 #endif /* REF_FILTER_H */