ref-filter: add shortcut to work with strbufs
authorOlga Telezhnaya <olyatelezhnaya@gmail.com>
Thu, 29 Mar 2018 12:49:45 +0000 (12:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Mar 2018 21:24:47 +0000 (14:24 -0700)
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>
ref-filter.c
index 45fc56216aaa8fd084a10514f6f4912878ab1627..0c8d1589cf316f77f6b727a0830569a3495d0f88 100644 (file)
@@ -101,6 +101,19 @@ static struct used_atom {
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
 
+/*
+ * Expand string, append it to strbuf *sb, then return error code ret.
+ * Allow to save few lines of code.
+ */
+static int strbuf_addf_ret(struct strbuf *sb, int ret, const char *fmt, ...)
+{
+       va_list ap;
+       va_start(ap, fmt);
+       strbuf_vaddf(sb, fmt, ap);
+       va_end(ap);
+       return ret;
+}
+
 static void color_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *color_value)
 {
        if (!color_value)