On Thu, Dec 08, 2016 at 01:03:27PM -0800, Stefan Beller wrote:
> +/*
> + * NEEDSWORK: The values in the returned worktrees are broken, e.g.
> + * the refs or path resolution is influenced by the current repository.
> + */
> +static struct worktree **get_submodule_worktrees(const char *path, unsigned 
> flags)

I'm ok with this (at least we know the function is half-broken). But I
wonder if we could go simpler, with something like this. It's more
efficient as well. And we can replace its implementation with
get_worktrees() or something when we are able to.

As long as this function stays in worktree.c I think it's ok for it to
peek into "worktrees" directory directly. That's what all other
functions in this file do after all.

int submodule_uses_worktrees(const char *path)
{
        struct strbuf path = STRBUF_INIT;
        DIR *dir;
        struct dirent *d;
        int ret = 0;

        strbuf_addf(&path, "%s/worktrees", path);
        dir = opendir(path.buf);
        strbuf_release(&path);

        if (!dir)
                return 0;

        while ((d = readdir(dir)) != NULL) {
                if (is_dot_or_dotdot(d->d_name))
                        continue;

                ret = 1;
                break;
        }
        closedir(dir);
        return ret;
}
--
Duy

Reply via email to