Re: [PATCH v3 05/13] worktree.c: mark current worktree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 6, 2016 at 2:51 PM, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
> On Fri, Apr 22, 2016 at 9:01 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
>> ---
>> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]