git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5 1/6] strbuf: add shortcut to work with error messages

From
Оля Тележная <olyatelezhnaya@gmail.com>
Date
Mar 23, 2018, 06:48 UTC
Message-ID
<CAL21Bm=M-X8pjnxKzXKZbwArF6gyoPLLLa8JBZFNrvwrsRsacg@mail.gmail.com>
In-Reply-To
<xmqqlgelnpsx.fsf@gitster-ct.c.googlers.com>
2018-03-21 23:20 GMT+03:00 Junio C Hamano <gitster@pobox.com>:
Show 50 quoted lines
> Olga Telezhnaya <olyatelezhnaya@gmail.com> writes:
>
>> Add function strbuf_error() that helps to save few lines of code.
>> Function expands fmt with placeholders, append resulting error message
>> to strbuf *err, and return error code ret.
>>
>> Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
>> ---
>>  strbuf.h | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/strbuf.h b/strbuf.h
>> index e6cae5f4398c8..fa66d4835f1a7 100644
>> --- a/strbuf.h
>> +++ b/strbuf.h
>> @@ -620,4 +620,17 @@ char *xstrvfmt(const char *fmt, va_list ap);
>>  __attribute__((format (printf, 1, 2)))
>>  char *xstrfmt(const char *fmt, ...);
>>
>> +/*
>> + * Expand error message, append it to strbuf *err, then return error code ret.
>> + * Allow to save few lines of code.
>> + */
>> +static inline int strbuf_error(struct strbuf *err, int ret, const char *fmt, ...)
>> +{
>
> With this function, err does not have to be an error message, and
> ret does not have to be negative.  Hence strbuf_error() is a wrong
> name for the wrapper.
>
> It somewhat is bothersome to see that this is inlined; if it is
> meant for error codepath, it probably shouldn't have to be.
>
>> +     va_list ap;
>> +     va_start(ap, fmt);
>> +     strbuf_vaddf(err, fmt, ap);
>> +     va_end(ap);
>> +     return ret;
>> +}
>> +
>>  #endif /* STRBUF_H */
>
> Quite honestly, I am not sure if it is worth to be in strbuf.h; it
> feels a bit too specific to the immediate need for these five
> patches and nowhere else.  Are there many existing calls to
> strbuf_addf() immediately followed by an "return" of an integer,
> that can be simplified by using this helper?  I see quite a many
> instances of addf() soon followed by "return -1" in
> refs/files-backend.c, but they are not immediately adjacent to each
> other, and won't be helped.

Summarizing all that we discussed: I have 2 options how to continue this patch. I can revert to v4, or I can replace new function in strbuf.h with similar macro in ref-filter.c (I mean, there would be no changes in strbuf.h and one new macro in ref-filter.c). What do you like more?

Thanks! Olga

Previous: Junio C Hamano
Message 10 of 10 in “strbuf: add shortcut to work with error messages”
  1. 1/6 strbuf: add shortcut to work with error messagesOlga Telezhnaya, Mar 21, 2018
  2. 4/6 ref-filter: change parsing function error handlingOlga Telezhnaya, Mar 21, 2018
  3. Junio C HamanoMar 21, 2018
  4. Оля ТележнаяMar 23, 2018
  5. 5/6 ref-filter: add return value to parsersOlga Telezhnaya, Mar 21, 2018
  6. 2/6 ref-filter: start adding strbufs with errorsOlga Telezhnaya, Mar 21, 2018
  7. 6/6 ref-filter: libify get_ref_atom_value()Olga Telezhnaya, Mar 21, 2018
  8. 3/6 ref-filter: add return value && strbuf to handlersOlga Telezhnaya, Mar 21, 2018
  9. Junio C HamanoMar 21, 2018
  10. Оля ТележнаяMar 23, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.