ref-filter: add shortcut to work with strbufs

Add function strbuf_addf_ret() that helps to save a few lines of code. Function expands fmt with placeholders, append resulting message to strbuf *sb, and return error code ret. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Olga Telezhnaya committed Mar 29, 2018 at 12:49 UTC e2e7a245459391a06a11b70282177135b3fe111c
1 file changed +13
ref-filter.c
+13
@@ -101,6 +101,19 @@ static struct used_atom {
101 } *used_atom;
102 static int used_atom_cnt, need_tagged, need_symref;
103
104 +/*
105 + * Expand string, append it to strbuf *sb, then return error code ret.
106 + * Allow to save few lines of code.
107 + */
108 +static int strbuf_addf_ret(struct strbuf *sb, int ret, const char *fmt, ...)
109 +{
110 + va_list ap;
111 + va_start(ap, fmt);
112 + strbuf_vaddf(sb, fmt, ap);
113 + va_end(ap);
114 + return ret;
115 +}
116 +
117 static void color_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *color_value)
118 {
119 if (!color_value)