Skip to content

Commit 99c6a71

Browse files
KarthikNayakgitster
authored andcommitted
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 <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d4919bb commit 99c6a71

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

ref-filter.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,10 +1833,10 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting
18331833
}
18341834
}
18351835

1836-
void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style)
1836+
void format_ref_array_item(struct ref_array_item *info, const char *format,
1837+
int quote_style, struct strbuf *final_buf)
18371838
{
18381839
const char *cp, *sp, *ep;
1839-
struct strbuf *final_buf;
18401840
struct ref_formatting_state state = REF_FORMATTING_STATE_INIT;
18411841

18421842
state.quote_style = quote_style;
@@ -1866,9 +1866,17 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
18661866
}
18671867
if (state.stack->prev)
18681868
die(_("format: %%(end) atom missing"));
1869-
final_buf = &state.stack->output;
1870-
fwrite(final_buf->buf, 1, final_buf->len, stdout);
1869+
strbuf_addbuf(final_buf, &state.stack->output);
18711870
pop_stack_element(&state.stack);
1871+
}
1872+
1873+
void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style)
1874+
{
1875+
struct strbuf final_buf = STRBUF_INIT;
1876+
1877+
format_ref_array_item(info, format, quote_style, &final_buf);
1878+
fwrite(final_buf.buf, 1, final_buf.len, stdout);
1879+
strbuf_release(&final_buf);
18721880
putchar('\n');
18731881
}
18741882

ref-filter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ int parse_ref_filter_atom(const char *atom, const char *ep);
100100
int verify_ref_format(const char *format);
101101
/* Sort the given ref_array as per the ref_sorting provided */
102102
void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
103+
/* Based on the given format and quote_style, fill the strbuf */
104+
void format_ref_array_item(struct ref_array_item *info, const char *format,
105+
int quote_style, struct strbuf *final_buf);
103106
/* Print the ref using the given format and quote_style */
104107
void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style);
105108
/* Callback function for parsing the sort option */

0 commit comments

Comments
 (0)