Re: [PATCH 4/8] worktree: drop useless call to strbuf_reset
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Sep 10, 2020, 19:49 UTC
- Message-ID
- <CAPig+cSEOUebNV90Gec2KqskZgAmX=jd++s4tfAyYN6Up4_O3A@mail.gmail.com>
- In-Reply-To
- <CAN0heSrQT9N3=e70qkgS_rOQ0oy0rrHqud=rRtr-r5JaL=ofNQ@mail.gmail.com>
On Thu, Sep 10, 2020 at 3:40 PM Martin Ågren <martin.agren@gmail.com> wrote:
Show 12 quoted lines
> On Thu, 10 Sep 2020 at 21:15, Eric Sunshine <sunshine@sunshineco.com> wrote: > > 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. > > That's not to say this optimization won't ever be useful, of course. I > also begin to hope that no caller keeps their returned pointer around > for long. It only seems to be used from `other_ref_heads()` and that > looks ok. If we do want this strbuf reuse, maybe that function could > just keep its own strbuf and reuse it (not necessarily having it be > static) and learn not to call `worktree_ref(wt, "HEAD")` twice.
Yep, I wouldn't be unhappy to see worktree_ref() disappear altogether. There are no external callers and it would be easy enough to retrofit the lone internal caller to use the safer strbuf_worktree_ref() anyhow. Plus, both calls to worktree_ref() in other_head_refs() invoke it with the exact same arguments, `worktree_ref(wt, "HEAD")`, which makes one wonder if it need be called twice at all in that particular scenario.