git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] log-tree: always use return value of strbuf_detach()
@ 2019-08-25 12:53 René Scharfe
  2019-08-26 18:46 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-08-25 12:53 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

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).

 log-tree.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

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);
 	}

 	/*
--
2.23.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] log-tree: always use return value of strbuf_detach()
  2019-08-25 12:53 [PATCH] log-tree: always use return value of strbuf_detach() René Scharfe
@ 2019-08-26 18:46 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2019-08-26 18:46 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano

On Sun, Aug 25, 2019 at 02:53:26PM +0200, René Scharfe wrote:

> 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. :)

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-26 18:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-25 12:53 [PATCH] log-tree: always use return value of strbuf_detach() René Scharfe
2019-08-26 18:46 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).