4 #include "sha1-array.h"
7 #include "parse-options.h"
13 #define QUOTE_PYTHON 4
16 #define FILTER_REFS_INCLUDE_BROKEN 0x0001
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)
29 struct ref_sorting *next;
30 int atom; /* index into used_atom array (internal) */
36 struct ref_array_item {
41 struct commit *commit;
42 struct atom_value *value;
43 enum object_type type;
47 struct object_id *delta_base_oid;
48 const char *objectname;
49 char refname[FLEX_ARRAY];
54 struct ref_array_item **items;
55 struct rev_info *revs;
59 const char **name_patterns;
60 struct oid_array points_at;
61 struct commit_list *with_commit;
62 struct commit_list *no_commit;
64 struct string_list with_commit_strs;
65 struct string_list no_commit_strs;
68 REF_FILTER_MERGED_NONE = 0,
69 REF_FILTER_MERGED_INCLUDE,
70 REF_FILTER_MERGED_OMIT
72 struct commit *merge_commit;
74 unsigned int with_commit_tag_algo : 1,
86 enum object_type type;
90 struct object_id delta_base_oid;
93 * After a mark_query run, this object_info is set up to be
94 * passed to sha1_object_info_extended. It will point to the data
95 * elements above, so you can retrieve the response from there.
97 struct object_info info;
100 * This flag will be true if the requested batch format and options
101 * don't require us to call sha1_object_info, which can then be
104 unsigned skip_object_info : 1;
105 unsigned is_cat_file : 1;
110 * Set these to define the format; make sure you call
111 * verify_ref_format() afterwards to finalize.
117 /* Internal state to ref-filter */
118 int need_color_reset_at_eol;
120 unsigned all_objects : 1;
121 unsigned is_cat_file : 1;
124 #define REF_FORMAT_INIT { NULL, 0, -1 }
126 /* Macros for checking --merged and --no-merged options */
127 #define _OPT_MERGED_NO_MERGED(option, filter, h) \
128 { OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
129 PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
130 parse_opt_merge_filter, (intptr_t) "HEAD" \
132 #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
133 #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
136 * API for filtering a set of refs. Based on the type of refs the user
137 * has requested, we iterate through those refs and apply filters
138 * as per the given ref_filter structure and finally store the
139 * filtered refs in the ref_array structure.
141 int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type);
142 /* Clear all memory allocated to ref_array */
143 void ref_array_clear(struct ref_array *array);
144 /* Used to verify if the given format is correct and to parse out the used atoms */
145 int verify_ref_format(struct ref_format *format);
146 /* Sort the given ref_array as per the ref_sorting provided */
147 void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
149 * Based on the given format and quote_style, fill the strbuf.
150 * Return 0 if everything was successful, -1 otherwise (and strbuf remains empty)
152 int format_ref_array_item(struct ref_array_item *info,
153 const struct ref_format *format,
154 struct strbuf *final_buf);
156 * Print the ref using the given format and quote_style.
157 * Return 0 if everything was successful, -1 otherwise.
159 int show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
160 /* Parse a single sort specifier and add it to the list */
161 void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
162 /* Callback function for parsing the sort option */
163 int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
164 /* Default sort option based on refname */
165 struct ref_sorting *ref_default_sorting(void);
166 /* Function to parse --merged and --no-merged options */
167 int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
168 /* Get the current HEAD's description */
169 char *get_head_description(void);
170 /* Set up translated strings in the output. */
171 void setup_ref_filter_porcelain_msg(void);
174 * Print a single ref, outside of any ref-filter. Note that the
175 * name must be a fully qualified refname.
177 void pretty_print_ref(const char *name, const unsigned char *sha1,
178 const struct ref_format *format);
180 /* Search for atom in given format. */
181 int is_atom_used(const struct ref_format *format, const char *atom);
183 #endif /* REF_FILTER_H */