aboutsummaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-07-13 11:01:18 -0400
committerJunio C Hamano <gitster@pobox.com>2017-07-13 12:42:50 -0700
commit4a68e36d7d106abaf44e3ac960276145b5a25723 (patch)
treee31869cd9a8b21809edc0e7fd77f9f133283da7f /ref-filter.c
parent51331aad69a1d89a8b6d1ff82bb5fedbdb6ccc6a (diff)
downloadgit-4a68e36d7d106abaf44e3ac960276145b5a25723.tar.gz
git-4a68e36d7d106abaf44e3ac960276145b5a25723.tar.xz
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 6da5be3ac..66d234bb1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -657,12 +657,12 @@ static const char *find_next(const char *cp)
* Make sure the format string is well formed, and parse out
* the used atoms.
*/
-int verify_ref_format(const char *format)
+int verify_ref_format(struct ref_format *format)
{
const char *cp, *sp;
need_color_reset_at_eol = 0;
- for (cp = format; *cp && (sp = find_next(cp)); ) {
+ for (cp = format->format; *cp && (sp = find_next(cp)); ) {
const char *color, *ep = strchr(sp, ')');
int at;
@@ -2060,16 +2060,17 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting
}
}
-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)
{
const char *cp, *sp, *ep;
struct ref_formatting_state state = REF_FORMATTING_STATE_INIT;
- state.quote_style = quote_style;
+ state.quote_style = format->quote_style;
push_stack_element(&state.stack);
- for (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {
+ for (cp = format->format; *cp && (sp = find_next(cp)); cp = ep + 1) {
struct atom_value *atomv;
ep = strchr(sp, ')');
@@ -2093,23 +2094,24 @@ void format_ref_array_item(struct ref_array_item *info, const char *format,
pop_stack_element(&state.stack);
}
-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)
{
struct strbuf final_buf = STRBUF_INIT;
- format_ref_array_item(info, format, quote_style, &final_buf);
+ format_ref_array_item(info, format, &final_buf);
fwrite(final_buf.buf, 1, final_buf.len, stdout);
strbuf_release(&final_buf);
putchar('\n');
}
void pretty_print_ref(const char *name, const unsigned char *sha1,
- const char *format)
+ const struct ref_format *format)
{
struct ref_array_item *ref_item;
ref_item = new_ref_array_item(name, sha1, 0);
ref_item->kind = ref_kind_from_refname(name);
- show_ref_array_item(ref_item, format, 0);
+ show_ref_array_item(ref_item, format);
free_array_item(ref_item);
}