Re: [PATCH v3 05/13] worktree.c: mark current worktree
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- May 6, 2016, 10:21 UTC
- Message-ID
- <CACsJy8D+anuZ-278kaz2ewpcLCGOSrdn2Qq1F7fFTuVUTLv5Yw@mail.gmail.com>
- In-Reply-To
- <CAPig+cQszEZLaebwqXNny6_EnhFpwU1xYqEX2_0N=vTEXTk2Fw@mail.gmail.com>
On Fri, May 6, 2016 at 2:51 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 32 quoted lines
> On Fri, Apr 22, 2016 at 9:01 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>> diff --git a/worktree.c b/worktree.c
>> @@ -147,6 +150,25 @@ done:
>> +static void mark_current_worktree(struct worktree **worktrees)
>> +{
>> + struct strbuf git_dir = STRBUF_INIT;
>> + struct strbuf path = STRBUF_INIT;
>> + int i;
>> +
>> + strbuf_addstr(&git_dir, absolute_path(get_git_dir()));
>
> This could also just be:
>
> char *git_dir = xstrdup(absolute_path(...));
>
> with a corresponding 'free(git_dir)' below.
>
>> + for (i = 0; worktrees[i]; i++) {
>> + struct worktree *wt = worktrees[i];
>> + strbuf_addstr(&path, absolute_path(get_worktree_git_dir(wt)));
>> + wt->is_current = !fspathcmp(git_dir.buf, path.buf);
>
> Similarly, it looks like 'path' doesn't need to be a strbuf at all
> since the result of absolute_path() should remain valid long enough
> for fspathcmp(). It could just be:
>
> const char *path = absolute_path(...);
> wt->is_current = !fspathcmp(git_dir, path);
>
> But these are very minor; probably not worth a re-roll.Yeah. I think the use of strbuf is influenced by the code in get_worktrees(). But since this code is now in a separate function, it makes little sense to go with the strbuf hammer. If there's no big change in this series, I'll just do this as a cleanup step in my next series, worktree-move.
-- Duy