From 82f51af3452bb80e2347bb45dba3e1d2f10d0be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 25 Aug 2019 14:53:26 +0200 Subject: [PATCH 1/2] log-tree: always use return value of strbuf_detach() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- 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, ¬ebuf, get_log_output_encoding(), raw); - ctx.notes_message = notebuf.len - ? strbuf_detach(¬ebuf, NULL) - : xcalloc(1, 1); + ctx.notes_message = strbuf_detach(¬ebuf, NULL); } /* From fd99c2dd9b0b24fe4bb36366a6b1ff9e29b29286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 25 Aug 2019 15:26:40 +0200 Subject: [PATCH 2/2] grep: use return value of strbuf_detach() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Append the strbuf buffer only after detaching it. There is no practical difference here, as the strbuf is not empty and no strbuf_ function is called between storing the pointer to the still attached buffer and calling strbuf_detach(), so that pointer is valid, but make sure to follow the standard sequence anyway for consistency. Signed-off-by: RenĂ© Scharfe Acked-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin/grep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 2699001fbd..69ac053acc 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1110,8 +1110,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) strbuf_addf(&buf, "+/%s%s", strcmp("less", pager) ? "" : "*", opt.pattern_list->pattern); - string_list_append(&path_list, buf.buf); - strbuf_detach(&buf, NULL); + string_list_append(&path_list, + strbuf_detach(&buf, NULL)); } }