path: root/ref-filter.c
diff options
authorKarthik Nayak <>2017-01-10 08:49:39 (GMT)
committerJunio C Hamano <>2017-01-10 20:44:31 (GMT)
commit99c6a71d4f7f4197f5e8600b0edec2a6a9fd9988 (patch)
treeacdc584bfd462d02aeb3ee893872f5d266833a69 /ref-filter.c
parentd4919bb288e46c81b92d6fe02c4f4564b8477fd3 (diff)
ref-filter: introduce format_ref_array_item()
To allow column display, we will need to first render the output in a string list to allow print_columns() to compute the proper size of each column before starting the actual output. Introduce the function format_ref_array_item() that does the formatting of a ref_array_item to an strbuf. show_ref_array_item() is kept as a convenience wrapper around it which obtains the strbuf and prints it the standard output. Mentored-by: Christian Couder <> Mentored-by: Matthieu Moy <> Signed-off-by: Karthik Nayak <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'ref-filter.c')
1 files changed, 12 insertions, 4 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 7038703..92c2d4f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1833,10 +1833,10 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting
-void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style)
+void format_ref_array_item(struct ref_array_item *info, const char *format,
+ int quote_style, struct strbuf *final_buf)
const char *cp, *sp, *ep;
- struct strbuf *final_buf;
struct ref_formatting_state state = REF_FORMATTING_STATE_INIT;
state.quote_style = quote_style;
@@ -1866,9 +1866,17 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
if (state.stack->prev)
die(_("format: %%(end) atom missing"));
- final_buf = &state.stack->output;
- fwrite(final_buf->buf, 1, final_buf->len, stdout);
+ strbuf_addbuf(final_buf, &state.stack->output);
+void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style)
+ struct strbuf final_buf = STRBUF_INIT;
+ format_ref_array_item(info, format, quote_style, &final_buf);
+ fwrite(final_buf.buf, 1, final_buf.len, stdout);
+ strbuf_release(&final_buf);