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

Re: [PATCH] log-tree: always use return value of strbuf_detach()

From
Jeff King <peff@peff.net>
Date
Aug 26, 2019, 18:46 UTC
Message-ID
<20190826184621.GE23399@sigill.intra.peff.net>
In-Reply-To
<dc471768-7f42-3e51-6397-1c40466d3726@web.de>
On Sun, Aug 25, 2019 at 02:53:26PM +0200, René Scharfe wrote:
Show 9 quoted lines
> strbuf_detach() has been returning a pointer to a buffer even for empty
> strbufs since 08ad56f3f0 ("strbuf: always return a non-NULL value from
> strbuf_detach", 2012-10-18).  Use that feature in show_log() instead of
> having it handle empty strbufs specially.
> 
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> The patched code was added one day earlier, by ddf333f66c ("pretty:
> prepare notes message at a centralized place", 2012-10-17).
Bad timing, I guess. :)
Show 13 quoted lines
> diff --git a/log-tree.c b/log-tree.c
> index 1e56df62a7..109c212224 100644
> --- a/log-tree.c
> +++ b/log-tree.c
> @@ -677,9 +677,7 @@ void show_log(struct rev_info *opt)
>  		raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
>  		format_display_notes(&commit->object.oid, &notebuf,
>  				     get_log_output_encoding(), raw);
> -		ctx.notes_message = notebuf.len
> -			? strbuf_detach(&notebuf, NULL)
> -			: xcalloc(1, 1);
> +		ctx.notes_message = strbuf_detach(&notebuf, NULL);
>  	}
Yeah, this is definitely the right thing to do.
-Peff
Previous: René Scharfe
Message 2 of 2 in “log-tree: always use return value of strbuf_detach()”
  1. log-tree: always use return value of strbuf_detach()René Scharfe, Aug 25, 2019
  2. Jeff KingAug 26, 2019

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.