On Thu, Dec 8, 2016 at 2:51 AM, Duy Nguyen <[email protected]> wrote:
> On Thu, Dec 8, 2016 at 5:40 PM, Duy Nguyen <[email protected]> wrote:
>> Alternatively, we could add a new flag to get_worktrees() to tell it
>> to return all worktrees if there is a least one linked worktree, or
>> return NULL if there's only main worktree. I'm not sure if this is
>> clever or very stupid.
>
> No, this may be better. Add a flag to say "returns linked worktrees
> _only_". Which means when you're in a "normal" repo, get_worktrees()
> with this flag returns NULL. When you're in a multiple-worktree repo,
> it returns all linked worktrees (no main worktree). I think I might
> have a use for this flag in addition to this uses_worktrees() here.
> uses_worktrees() look quite simple with that flag
>
> int uses_worktrees(void)
> {
> struct worktree **worktrees = get_worktrees(WT_LINKED_ONLY);
> int retval = worktrees != NULL;
I am interested in the submodule case however, where we already return NULL
e.g. when the submodule git dir cannot be found. Actually that would
work out fine
as well:
/* NOTE on accuracy of result, hence not exposed. */
static worktree **submodule_get_worktrees(const char *path, unsigned flags)
..
int submodule_uses_worktrees(const char *path)
{
struct worktree **worktrees = submodule_get_worktrees(path,
WT_LINKED_ONLY);
int retval = worktrees != NULL;
free_worktrees(worktrees);
return retval;
}
Thanks for that inspiration!