ref-filter.h 4.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#ifndef REF_FILTER_H
#define REF_FILTER_H

#include "sha1-array.h"
#include "refs.h"
#include "commit.h"
#include "parse-options.h"

/* Quoting styles */
#define QUOTE_NONE 0
#define QUOTE_SHELL 1
#define QUOTE_PERL 2
#define QUOTE_PYTHON 4
#define QUOTE_TCL 8

16 17 18 19 20 21 22 23 24
#define FILTER_REFS_INCLUDE_BROKEN 0x0001
#define FILTER_REFS_TAGS           0x0002
#define FILTER_REFS_BRANCHES       0x0004
#define FILTER_REFS_REMOTES        0x0008
#define FILTER_REFS_OTHERS         0x0010
#define FILTER_REFS_ALL            (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \
				    FILTER_REFS_REMOTES | FILTER_REFS_OTHERS)
#define FILTER_REFS_DETACHED_HEAD  0x0020
#define FILTER_REFS_KIND_MASK      (FILTER_REFS_ALL | FILTER_REFS_DETACHED_HEAD)
25

26
struct atom_value;
27 28 29 30

struct ref_sorting {
	struct ref_sorting *next;
	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 objectname;
38
	int flag;
39
	unsigned int kind;
40
	const char *symref;
41
	struct commit *commit;
42
	struct atom_value *value;
43
	char refname[FLEX_ARRAY];
44 45 46 47 48
};

struct ref_array {
	int nr, alloc;
	struct ref_array_item **items;
49
	struct rev_info *revs;
50 51 52 53
};

struct ref_filter {
	const char **name_patterns;
54
	struct oid_array points_at;
55
	struct commit_list *with_commit;
56
	struct commit_list *no_commit;
57 58 59 60 61 62 63

	enum {
		REF_FILTER_MERGED_NONE = 0,
		REF_FILTER_MERGED_INCLUDE,
		REF_FILTER_MERGED_OMIT
	} merge;
	struct commit *merge_commit;
64

65
	unsigned int with_commit_tag_algo : 1,
66
		match_as_path : 1,
67
		ignore_case : 1,
68
		detached : 1;
69 70
	unsigned int kind,
		lines;
71 72
	int abbrev,
		verbose;
73 74
};

75 76 77 78 79 80 81
struct ref_format {
	/*
	 * Set these to define the format; make sure you call
	 * verify_ref_format() afterwards to finalize.
	 */
	const char *format;
	int quote_style;
82
	int use_color;
83 84 85

	/* Internal state to ref-filter */
	int need_color_reset_at_eol;
86 87
};

88
#define REF_FORMAT_INIT { NULL, 0, -1 }
89

90 91 92 93 94 95 96 97 98
/*  Macros for checking --merged and --no-merged options */
#define _OPT_MERGED_NO_MERGED(option, filter, h) \
	{ OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
	  PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
	  parse_opt_merge_filter, (intptr_t) "HEAD" \
	}
#define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
#define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)

99 100 101 102 103
#define OPT_REF_SORT(var) \
	OPT_CALLBACK_F(0, "sort", (var), \
		       N_("key"), N_("field name to sort on"), \
		       PARSE_OPT_NONEG, parse_opt_ref_sorting)

104 105 106 107 108 109 110
/*
 * API for filtering a set of refs. Based on the type of refs the user
 * has requested, we iterate through those refs and apply filters
 * as per the given ref_filter structure and finally store the
 * filtered refs in the ref_array structure.
 */
int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type);
111 112 113
/*  Clear all memory allocated to ref_array */
void ref_array_clear(struct ref_array *array);
/*  Used to verify if the given format is correct and to parse out the used atoms */
114
int verify_ref_format(struct ref_format *format);
115 116
/*  Sort the given ref_array as per the ref_sorting provided */
void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
117
/*  Based on the given format and quote_style, fill the strbuf */
118 119 120 121
int format_ref_array_item(struct ref_array_item *info,
			  const struct ref_format *format,
			  struct strbuf *final_buf,
			  struct strbuf *error_buf);
122
/*  Print the ref using the given format and quote_style */
123
void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
124 125
/*  Parse a single sort specifier and add it to the list */
void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
126 127 128 129
/*  Callback function for parsing the sort option */
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
/*  Default sort option based on refname */
struct ref_sorting *ref_default_sorting(void);
130 131
/*  Function to parse --merged and --no-merged options */
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
132 133
/*  Get the current HEAD's description */
char *get_head_description(void);
134 135
/*  Set up translated strings in the output. */
void setup_ref_filter_porcelain_msg(void);
136

137 138 139 140
/*
 * Print a single ref, outside of any ref-filter. Note that the
 * name must be a fully qualified refname.
 */
141
void pretty_print_ref(const char *name, const struct object_id *oid,
142
		      const struct ref_format *format);
143

144 145 146 147 148 149 150 151
/*
 * Push a single ref onto the array; this can be used to construct your own
 * ref_array without using filter_refs().
 */
struct ref_array_item *ref_array_push(struct ref_array *array,
				      const char *refname,
				      const struct object_id *oid);

152
#endif /*  REF_FILTER_H  */