Merge branch 'ab/remove-implicit-use-of-the-repository'
[git.git] / ref-filter.h
blobae51ace3a2099427daee953a1b778542d94361ec
1 #ifndef REF_FILTER_H
2 #define REF_FILTER_H
4 #include "oid-array.h"
5 #include "refs.h"
6 #include "commit.h"
7 #include "string-list.h"
9 /* Quoting styles */
10 #define QUOTE_NONE 0
11 #define QUOTE_SHELL 1
12 #define QUOTE_PERL 2
13 #define QUOTE_PYTHON 4
14 #define QUOTE_TCL 8
16 #define FILTER_REFS_TAGS 0x0002
17 #define FILTER_REFS_BRANCHES 0x0004
18 #define FILTER_REFS_REMOTES 0x0008
19 #define FILTER_REFS_OTHERS 0x0010
20 #define FILTER_REFS_ALL (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \
21 FILTER_REFS_REMOTES | FILTER_REFS_OTHERS)
22 #define FILTER_REFS_DETACHED_HEAD 0x0020
23 #define FILTER_REFS_KIND_MASK (FILTER_REFS_ALL | FILTER_REFS_DETACHED_HEAD)
25 struct atom_value;
26 struct ref_sorting;
27 struct ahead_behind_count;
28 struct option;
30 enum ref_sorting_order {
31 REF_SORTING_REVERSE = 1<<0,
32 REF_SORTING_ICASE = 1<<1,
33 REF_SORTING_VERSION = 1<<2,
34 REF_SORTING_DETACHED_HEAD_FIRST = 1<<3,
37 struct ref_array_item {
38 struct object_id objectname;
39 const char *rest;
40 int flag;
41 unsigned int kind;
42 const char *symref;
43 struct commit *commit;
44 struct atom_value *value;
45 struct ahead_behind_count **counts;
47 char refname[FLEX_ARRAY];
50 struct ref_array {
51 int nr, alloc;
52 struct ref_array_item **items;
53 struct rev_info *revs;
55 struct ahead_behind_count *counts;
56 size_t counts_nr;
59 struct ref_filter {
60 const char **name_patterns;
61 struct oid_array points_at;
62 struct commit_list *with_commit;
63 struct commit_list *no_commit;
64 struct commit_list *reachable_from;
65 struct commit_list *unreachable_from;
67 unsigned int with_commit_tag_algo : 1,
68 match_as_path : 1,
69 ignore_case : 1,
70 detached : 1;
71 unsigned int kind,
72 lines;
73 int abbrev,
74 verbose;
77 struct ref_format {
79 * Set these to define the format; make sure you call
80 * verify_ref_format() afterwards to finalize.
82 const char *format;
83 const char *rest;
84 int quote_style;
85 int use_rest;
86 int use_color;
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_FORMAT_INIT { \
96 .use_color = -1, \
97 .bases = STRING_LIST_INIT_DUP, \
100 /* Macros for checking --merged and --no-merged options */
101 #define _OPT_MERGED_NO_MERGED(option, filter, h) \
102 { OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
103 PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
104 parse_opt_merge_filter, (intptr_t) "HEAD" \
106 #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
107 #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
109 #define OPT_REF_SORT(var) \
110 OPT_STRING_LIST(0, "sort", (var), \
111 N_("key"), N_("field name to sort on"))
114 * API for filtering a set of refs. Based on the type of refs the user
115 * has requested, we iterate through those refs and apply filters
116 * as per the given ref_filter structure and finally store the
117 * filtered refs in the ref_array structure.
119 int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type);
120 /* Clear all memory allocated to ref_array */
121 void ref_array_clear(struct ref_array *array);
122 /* Used to verify if the given format is correct and to parse out the used atoms */
123 int verify_ref_format(struct ref_format *format);
124 /* Sort the given ref_array as per the ref_sorting provided */
125 void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
126 /* Set REF_SORTING_* sort_flags for all elements of a sorting list */
127 void ref_sorting_set_sort_flags_all(struct ref_sorting *sorting, unsigned int mask, int on);
128 /* Based on the given format and quote_style, fill the strbuf */
129 int format_ref_array_item(struct ref_array_item *info,
130 struct ref_format *format,
131 struct strbuf *final_buf,
132 struct strbuf *error_buf);
133 /* Release a "struct ref_sorting" */
134 void ref_sorting_release(struct ref_sorting *);
135 /* Convert list of sort options into ref_sorting */
136 struct ref_sorting *ref_sorting_options(struct string_list *);
137 /* Function to parse --merged and --no-merged options */
138 int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
139 /* Get the current HEAD's description */
140 char *get_head_description(void);
141 /* Set up translated strings in the output. */
142 void setup_ref_filter_porcelain_msg(void);
145 * Print a single ref, outside of any ref-filter. Note that the
146 * name must be a fully qualified refname.
148 void pretty_print_ref(const char *name, const struct object_id *oid,
149 struct ref_format *format);
152 * Push a single ref onto the array; this can be used to construct your own
153 * ref_array without using filter_refs().
155 struct ref_array_item *ref_array_push(struct ref_array *array,
156 const char *refname,
157 const struct object_id *oid);
160 * If the provided format includes ahead-behind atoms, then compute the
161 * ahead-behind values for the array of filtered references. Must be
162 * called after filter_refs() but before outputting the formatted refs.
164 * If this is not called, then any ahead-behind atoms will be blank.
166 void filter_ahead_behind(struct repository *r,
167 struct ref_format *format,
168 struct ref_array *array);
170 #endif /* REF_FILTER_H */