ref-filter: add 'ref-filter.h'

This is step one of creating a common library for 'for-each-ref', 'branch -l' and 'tag -l'. This creates a header file with the functions and data structures that ref-filter will provide. We move the data structures created in for-each-ref to this header file. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Jun 14, 2015 at 01:07 UTC 69b1cf91e50808df4424c563b1256665034baec8
2 files changed +67 -40
builtin/for-each-ref.c
+1 -40
@@ -10,49 +10,10 @@
10 #include "parse-options.h"
11 #include "remote.h"
12 #include "color.h"
13 -
14 -/* Quoting styles */
15 -#define QUOTE_NONE 0
16 -#define QUOTE_SHELL 1
17 -#define QUOTE_PERL 2
18 -#define QUOTE_PYTHON 4
19 -#define QUOTE_TCL 8
13 +#include "ref-filter.h"
14
15 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
16
23 -struct atom_value {
24 - const char *s;
25 - unsigned long ul; /* used for sorting when not FIELD_STR */
26 -};
27 -
28 -struct ref_sort {
29 - struct ref_sort *next;
30 - int atom; /* index into used_atom array */
31 - unsigned reverse : 1;
32 -};
33 -
34 -struct ref_array_item {
35 - unsigned char objectname[20];
36 - int flag;
37 - const char *symref;
38 - struct atom_value *value;
39 - char *refname;
40 -};
41 -
42 -struct ref_array {
43 - int nr, alloc;
44 - struct ref_array_item **items;
45 -};
46 -
47 -struct ref_filter {
48 - const char **name_patterns;
49 -};
50 -
51 -struct ref_filter_cbdata {
52 - struct ref_array array;
53 - struct ref_filter filter;
54 -};
55 -
17 static struct {
18 const char *name;
19 cmp_type cmp_type;
ref-filter.h new
+66
@@ -0,0 +1,66 @@
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 +struct atom_value {
17 + const char *s;
18 + unsigned long ul; /* used for sorting when not FIELD_STR */
19 +};
20 +
21 +struct ref_sorting {
22 + struct ref_sorting *next;
23 + int atom; /* index into used_atom array (internal) */
24 + unsigned reverse : 1;
25 +};
26 +
27 +struct ref_array_item {
28 + unsigned char objectname[20];
29 + int flag;
30 + const char *symref;
31 + struct atom_value *value;
32 + char *refname;
33 +};
34 +
35 +struct ref_array {
36 + int nr, alloc;
37 + struct ref_array_item **items;
38 +};
39 +
40 +struct ref_filter {
41 + const char **name_patterns;
42 +};
43 +
44 +struct ref_filter_cbdata {
45 + struct ref_array array;
46 + struct ref_filter filter;
47 +};
48 +
49 +/* Callback function for for_each_*ref(). This filters the refs based on the filters set */
50 +int ref_filter_handler(const char *refname, const struct object_id *oid, int flag, void *cb_data);
51 +/* Clear all memory allocated to ref_array */
52 +void ref_array_clear(struct ref_array *array);
53 +/* Parse format string and sort specifiers */
54 +int parse_ref_filter_atom(const char *atom, const char *ep);
55 +/* Used to verify if the given format is correct and to parse out the used atoms */
56 +int verify_ref_format(const char *format);
57 +/* Sort the given ref_array as per the ref_sorting provided */
58 +void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
59 +/* Print the ref using the given format and quote_style */
60 +void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style);
61 +/* Callback function for parsing the sort option */
62 +int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
63 +/* Default sort option based on refname */
64 +struct ref_sorting *ref_default_sorting(void);
65 +
66 +#endif /* REF_FILTER_H */