path: root/ref-filter.h
diff options
authorJeff King <>2017-07-13 15:01:18 (GMT)
committerJunio C Hamano <>2017-07-13 19:42:50 (GMT)
commit4a68e36d7d106abaf44e3ac960276145b5a25723 (patch)
treee31869cd9a8b21809edc0e7fd77f9f133283da7f /ref-filter.h
parent51331aad69a1d89a8b6d1ff82bb5fedbdb6ccc6a (diff)
ref-filter: abstract ref format into its own struct
The ref-filter module provides routines for formatting a ref for output. The fundamental interface for the format is a "const char *" containing the format, and any additional options need to be passed to each invocation of show_ref_array_item. Instead, let's make a ref_format struct that holds the format, along with any associated format options. That will make some enhancements easier in the future: 1. new formatting options can be added without disrupting existing callers 2. some state can be carried in the struct rather than as global variables For now this just has the text format itself along with the quote_style option, but we'll add more fields in future patches. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'ref-filter.h')
1 files changed, 17 insertions, 5 deletions
diff --git a/ref-filter.h b/ref-filter.h
index 6552024..2bb5887 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -72,6 +72,17 @@ struct ref_filter {
+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;
+#define REF_FORMAT_INIT { NULL, 0 }
/* Macros for checking --merged and --no-merged options */
#define _OPT_MERGED_NO_MERGED(option, filter, h) \
{ OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
@@ -93,14 +104,15 @@ void ref_array_clear(struct ref_array *array);
/* Parse format string and sort specifiers */
int parse_ref_filter_atom(const char *atom, const char *ep);
/* Used to verify if the given format is correct and to parse out the used atoms */
-int verify_ref_format(const char *format);
+int verify_ref_format(struct ref_format *format);
/* Sort the given ref_array as per the ref_sorting provided */
void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
/* Based on the given format and quote_style, fill the strbuf */
-void format_ref_array_item(struct ref_array_item *info, const char *format,
- int quote_style, struct strbuf *final_buf);
+void format_ref_array_item(struct ref_array_item *info,
+ const struct ref_format *format,
+ struct strbuf *final_buf);
/* Print the ref using the given format and quote_style */
-void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style);
+void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
/* 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 */
@@ -117,6 +129,6 @@ void setup_ref_filter_porcelain_msg(void);
* name must be a fully qualified refname.
void pretty_print_ref(const char *name, const unsigned char *sha1,
- const char *format);
+ const struct ref_format *format);
#endif /* REF_FILTER_H */