Merge branch 'sg/subtree-signed-commits' into pu
[git] / ref-filter.h
1 #ifndef REF_FILTER_H
2 #define REF_FILTER_H
3
4 #include "sha1-array.h"
5 #include "refs.h"
6 #include "commit.h"
7 #include "parse-options.h"
8
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
15
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)
25
26 struct atom_value;
27
28 struct ref_sorting {
29         struct ref_sorting *next;
30         int atom; /* index into used_atom array (internal) */
31         unsigned reverse : 1,
32                 ignore_case : 1,
33                 version : 1;
34 };
35
36 struct ref_array_item {
37         struct object_id oid;
38         int flag;
39         unsigned int kind;
40         const char *symref;
41         struct commit *commit;
42         struct atom_value *value;
43         enum object_type type;
44         unsigned long size;
45         off_t disk_size;
46         const char *rest;
47         struct object_id *delta_base_oid;
48         const char *objectname;
49         char refname[FLEX_ARRAY];
50 };
51
52 struct ref_array {
53         int nr, alloc;
54         struct ref_array_item **items;
55         struct rev_info *revs;
56 };
57
58 struct ref_filter {
59         const char **name_patterns;
60         struct oid_array points_at;
61         struct commit_list *with_commit;
62         struct commit_list *no_commit;
63
64         struct string_list with_commit_strs;
65         struct string_list no_commit_strs;
66
67         enum {
68                 REF_FILTER_MERGED_NONE = 0,
69                 REF_FILTER_MERGED_INCLUDE,
70                 REF_FILTER_MERGED_OMIT
71         } merge;
72         struct commit *merge_commit;
73
74         unsigned int with_commit_tag_algo : 1,
75                 match_as_path : 1,
76                 ignore_case : 1,
77                 detached : 1;
78         unsigned int kind,
79                 lines;
80         int abbrev,
81                 verbose;
82 };
83
84 struct expand_data {
85         struct object_id oid;
86         enum object_type type;
87         unsigned long size;
88         off_t disk_size;
89         const char *rest;
90         struct object_id delta_base_oid;
91
92         /*
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.
96          */
97         struct object_info info;
98
99         /*
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
102          * optimized out.
103          */
104         unsigned skip_object_info : 1;
105         unsigned is_cat_file : 1;
106 };
107
108 struct ref_format {
109         /*
110          * Set these to define the format; make sure you call
111          * verify_ref_format() afterwards to finalize.
112          */
113         const char *format;
114         int quote_style;
115         int use_color;
116
117         /* Internal state to ref-filter */
118         int need_color_reset_at_eol;
119
120         unsigned all_objects : 1;
121         unsigned is_cat_file : 1;
122 };
123
124 #define REF_FORMAT_INIT { NULL, 0, -1 }
125
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" \
131         }
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)
134
135 /*
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.
140  */
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);
148 /*
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)
151  */
152 int format_ref_array_item(struct ref_array_item *info,
153                            const struct ref_format *format,
154                            struct strbuf *final_buf);
155 /*
156  * Print the ref using the given format and quote_style.
157  * Return 0 if everything was successful, -1 otherwise.
158  */
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);
172
173 /*
174  * Print a single ref, outside of any ref-filter. Note that the
175  * name must be a fully qualified refname.
176  */
177 void pretty_print_ref(const char *name, const unsigned char *sha1,
178                       const struct ref_format *format);
179
180 /* Search for atom in given format. */
181 int is_atom_used(const struct ref_format *format, const char *atom);
182
183 #endif /*  REF_FILTER_H  */