Re: [PATCH 5/7] worktree.c: add clear_worktree()
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- May 11, 2016, 06:42 UTC
- Message-ID
- <CAPig+cSNvsJH5Ax3CD=z2VR5tUOY2CyzP-MgRHAH7CvQc51qmA@mail.gmail.com>
- In-Reply-To
- <CAPig+cS-tb_hD3k2XsTioJrkzaB3FxSnrxM6JMq5-og1ADnoRg@mail.gmail.com>
On Wed, May 11, 2016 at 2:36 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 31 quoted lines
> On Tue, May 10, 2016 at 10:15 AM, Nguyễn Thái Ngọc Duy
> <pclouds@gmail.com> wrote:
>> The use case is keep some worktree and discard the rest of the worktree
>> list.
>
> So, you're saying that rather than a client freeing the entire
> worktree list like this:
>
> free_worktrees(worktrees);
>
> it might instead want to keep some element ('n') and free all others
> plus the list itself, like this:
>
> struct worktree *keep = worktrees[n];
> struct worktree **p = worktrees;
> for (; *p; p++)
> if (*p != keep)
> clear_worktree(*p);
> free(worktrees);
>
> Is that correct?
>
> If so, then doesn't this require the client to have far too intimate
> knowledge of the internals of free_worktrees(). Or, was your idea that
> the client would simply leak the 'worktrees' array after freeing the
> unwanted elements?
>
> In either case, a cleaner approach might be to provide a function for
> copying a worktree element. Perhaps:
>
> struct worktree *copy_worktree(const struct worktree *);Of course, you'd still need a clear_worktree() or free_worktree() function to dispose of the copy.