Re: [PATCH v3 05/13] worktree.c: mark current worktree
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- May 6, 2016, 07:51 UTC
- Message-ID
- <CAPig+cQszEZLaebwqXNny6_EnhFpwU1xYqEX2_0N=vTEXTk2Fw@mail.gmail.com>
- In-Reply-To
- <1461330096-21783-6-git-send-email-pclouds@gmail.com>
On Fri, Apr 22, 2016 at 9:01 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 11 quoted lines
> 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.
Show 7 quoted lines
> + strbuf_reset(&path); > + if (wt->is_current) > + break; > + } > + strbuf_release(&git_dir); > + strbuf_release(&path); > +}