Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/ref-filter.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / ref-filter.h` 235 lines ยท 7344 bytes Raw Blame History 1 #ifndef REF_FILTER_H 2 #define REF_FILTER_H 3 4 #include "gettext.h" 5 #include "oid-array.h" 6 #include "commit.h" 7 #include "string-list.h" 8 #include "strvec.h" 9 #include "commit-reach.h" 10 11 /* Quoting styles */ 12 #define QUOTE_NONE 0 13 #define QUOTE_SHELL 1 14 #define QUOTE_PERL 2 15 #define QUOTE_PYTHON 4 16 #define QUOTE_TCL 8 17 18 #define FILTER_REFS_TAGS 0x0002 19 #define FILTER_REFS_BRANCHES 0x0004 20 #define FILTER_REFS_REMOTES 0x0008 21 #define FILTER_REFS_OTHERS 0x0010 22 #define FILTER_REFS_REGULAR (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \ 23 FILTER_REFS_REMOTES | FILTER_REFS_OTHERS) 24 #define FILTER_REFS_DETACHED_HEAD 0x0020 25 #define FILTER_REFS_PSEUDOREFS 0x0040 26 #define FILTER_REFS_ROOT_REFS 0x0080 27 #define FILTER_REFS_KIND_MASK (FILTER_REFS_REGULAR | FILTER_REFS_DETACHED_HEAD | \ 28 FILTER_REFS_PSEUDOREFS | FILTER_REFS_ROOT_REFS) 29 30 struct atom_value; 31 struct ref_sorting; 32 struct ahead_behind_count; 33 struct option; 34 35 enum ref_sorting_order { 36 REF_SORTING_REVERSE = 1<<0, 37 REF_SORTING_ICASE = 1<<1, 38 REF_SORTING_VERSION = 1<<2, 39 REF_SORTING_DETACHED_HEAD_FIRST = 1<<3, 40 }; 41 42 struct ref_array_item { 43 struct object_id objectname; 44 struct object_id peeled_oid; 45 const char *rest; 46 int flag; 47 unsigned int kind; 48 const char *symref; 49 struct commit *commit; 50 struct atom_value *value; 51 struct ahead_behind_count **counts; 52 char **is_base; 53 54 char refname[FLEX_ARRAY]; 55 }; 56 57 struct ref_array { 58 int nr, alloc; 59 struct ref_array_item **items; 60 struct rev_info *revs; 61 62 struct ahead_behind_count *counts; 63 size_t counts_nr; 64 }; 65 66 struct ref_filter { 67 const char **name_patterns; 68 const char *start_after; 69 struct strvec exclude; 70 struct strvec forked; 71 struct oid_array points_at; 72 struct commit_list *with_commit; 73 struct commit_list *no_commit; 74 struct commit_list *reachable_from; 75 struct commit_list *unreachable_from; 76 77 unsigned int with_commit_tag_algo : 1, 78 match_as_path : 1, 79 ignore_case : 1, 80 detached : 1; 81 unsigned int kind, 82 lines; 83 int abbrev, 84 verbose; 85 86 struct { 87 struct contains_cache contains_cache; 88 struct contains_cache no_contains_cache; 89 } internal; 90 }; 91 92 struct ref_format { 93 /* 94 * Set these to define the format; make sure you call 95 * verify_ref_format() afterwards to finalize. 96 */ 97 const char *format; 98 const char *rest; 99 int quote_style; 100 enum git_colorbool use_color; 101 102 /* Internal state to ref-filter */ 103 int need_color_reset_at_eol; 104 105 struct { 106 int max_count; 107 int omit_empty; 108 } array_opts; 109 }; 110 111 #define REF_FILTER_INIT { \ 112 .points_at = OID_ARRAY_INIT, \ 113 .exclude = STRVEC_INIT, \ 114 .forked = STRVEC_INIT, \ 115 } 116 #define REF_FORMAT_INIT { \ 117 .use_color = GIT_COLOR_UNKNOWN, \ 118 } 119 120 /* Macros for checking --merged and --no-merged options */ 121 #define _OPT_MERGED_NO_MERGED(option, filter, h) { \ 122 .type = OPTION_CALLBACK, \ 123 .long_name = option, \ 124 .value = (filter), \ 125 .argh = N_("commit"), \ 126 .help = (h), \ 127 .flags = PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \ 128 .callback = parse_opt_merge_filter, \ 129 .defval = (intptr_t) "HEAD", \ 130 } 131 #define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h) 132 #define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h) 133 134 #define OPT_REF_SORT(var) \ 135 OPT_STRING_LIST(0, "sort", (var), \ 136 N_("key"), N_("field name to sort on")) 137 #define OPT_REF_FILTER_EXCLUDE(var) \ 138 OPT_STRVEC(0, "exclude", &(var)->exclude, \ 139 N_("pattern"), N_("exclude refs which match pattern")) 140 141 /* Get the reference kind from the provided reference name. */ 142 int ref_kind_from_refname(const char *refname); 143 /* 144 * API for filtering a set of refs. Based on the type of refs the user 145 * has requested, we iterate through those refs and apply filters 146 * as per the given ref_filter structure and finally store the 147 * filtered refs in the ref_array structure. 148 */ 149 int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type); 150 /* 151 * Filter refs using the given ref_filter and type, sort the contents 152 * according to the given ref_sorting, format the filtered refs with the 153 * given ref_format, and print them to stdout. 154 */ 155 void filter_and_format_refs(struct ref_filter *filter, unsigned int type, 156 struct ref_sorting *sorting, 157 struct ref_format *format); 158 /* Clear all memory allocated to ref_array */ 159 void ref_array_clear(struct ref_array *array); 160 /* Used to verify if the given format is correct and to parse out the used atoms */ 161 int verify_ref_format(struct ref_format *format); 162 /* Sort the given ref_array as per the ref_sorting provided */ 163 void ref_array_sort(struct ref_sorting *sort, struct ref_array *array); 164 /* Set REF_SORTING_* sort_flags for all elements of a sorting list */ 165 void ref_sorting_set_sort_flags_all(struct ref_sorting *sorting, unsigned int mask, int on); 166 /* Based on the given format and quote_style, fill the strbuf */ 167 int format_ref_array_item(struct ref_array_item *info, 168 struct ref_format *format, 169 struct strbuf *final_buf, 170 struct strbuf *error_buf); 171 /* Release a "struct ref_sorting" */ 172 void ref_sorting_release(struct ref_sorting *); 173 /* Convert list of sort options into ref_sorting */ 174 struct ref_sorting *ref_sorting_options(struct string_list *); 175 /* Function to parse --merged and --no-merged options */ 176 int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset); 177 /* 178 * Register a --forked pattern on the filter. The argument is 179 * either a ref, which is resolved to its full refname, or a shell-style 180 * glob. Branches are kept only when their configured upstream matches 181 * one of the registered patterns. Returns -1 if the argument is not a 182 * valid ref or pattern. 183 */ 184 int ref_filter_forked_add(struct ref_filter *filter, const char *arg); 185 /* Get the current HEAD's description */ 186 char *get_head_description(void); 187 /* Set up translated strings in the output. */ 188 void setup_ref_filter_porcelain_msg(void); 189 190 /* 191 * Print up to maxcount ref_array elements to stdout using the given 192 * ref_format. 193 */ 194 void print_formatted_ref_array(struct ref_array *array, struct ref_format *format); 195 196 /* 197 * Print a single ref, outside of any ref-filter. Note that the 198 * name must be a fully qualified refname. 199 */ 200 void pretty_print_ref(const char *name, const struct object_id *oid, 201 const struct object_id *peeled_oid, 202 struct ref_format *format); 203 204 /* 205 * Push a single ref onto the array; this can be used to construct your own 206 * ref_array without using filter_refs(). 207 */ 208 struct ref_array_item *ref_array_push(struct ref_array *array, 209 const char *refname, 210 const struct object_id *oid, 211 const struct object_id *peeled_oid); 212 213 /* 214 * If the provided format includes ahead-behind atoms, then compute the 215 * ahead-behind values for the array of filtered references. Must be 216 * called after filter_refs() but before outputting the formatted refs. 217 * 218 * If this is not called, then any ahead-behind atoms will be blank. 219 */ 220 void filter_ahead_behind(struct repository *r, 221 struct ref_array *array); 222 223 /* 224 * If the provided format includes is-base atoms, then compute the base checks 225 * for those tips against all refs. 226 * 227 * If this is not called, then any is-base atoms will be blank. 228 */ 229 void filter_is_base(struct repository *r, 230 struct ref_array *array); 231 232 void ref_filter_init(struct ref_filter *filter); 233 void ref_filter_clear(struct ref_filter *filter); 234 235 #endif /* REF_FILTER_H */