Re: [PATCH 4/8] worktree: drop useless call to strbuf_reset
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Sep 10, 2020, 19:15 UTC
- Message-ID
- <CAPig+cTZLqFayp0wZEFYkaXtoOx8HedUK1oQoOa+zq=Yrgvjbg@mail.gmail.com>
- In-Reply-To
- <58a2469cc18839e57b45f687b6e484d69161a34c.1599762679.git.martin.agren@gmail.com>
On Thu, Sep 10, 2020 at 3:08 PM Martin Ågren <martin.agren@gmail.com> wrote:
Show 13 quoted lines
> There's no need to reset the strbuf immediately after initializing it.
>
> Signed-off-by: Martin Ågren <martin.agren@gmail.com>
> ---
> diff --git a/worktree.c b/worktree.c
> @@ -552,7 +552,6 @@ const char *worktree_ref(const struct worktree *wt, const char *refname)
> {
> static struct strbuf sb = STRBUF_INIT;
>
> - strbuf_reset(&sb);
> strbuf_worktree_ref(wt, &sb, refname);
> return sb.buf;
> }I think this patch is wrong and should be dropped. That strbuf is static, and the called strbuf_worktree_ref() does not reset it, so each call to worktree_ref() will now merely append to the existing content (which is undesirable) following this change.