git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Stefan Beller <sbeller@google.com>
Cc: Brandon Williams <bmwill@google.com>,
	Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCHv6 4/7] worktree: get worktrees from submodules
Date: Thu, 8 Dec 2016 17:09:58 +0700	[thread overview]
Message-ID: <CACsJy8Bs78ywGq5p6yAFGi1KACAXFEeroyQSJye5-RL5gqOS+Q@mail.gmail.com> (raw)
In-Reply-To: <20161208014623.7588-5-sbeller@google.com>

On Thu, Dec 8, 2016 at 8:46 AM, Stefan Beller <sbeller@google.com> wrote:
>
>         worktree = xcalloc(1, sizeof(*worktree));
>         worktree->path = strbuf_detach(&worktree_path, NULL);
> @@ -101,7 +101,8 @@ static struct worktree *get_main_worktree(void)

All the good stuff is outside context lines again.. Somewhere between
here we call add_head_info() which calls resolve_ref_unsafe(), which
always uses data from current repo, not the submodule we want it to
look at.

> @@ -167,7 +168,8 @@ static int compare_worktree(const void *a_, const void *b_)
>         return fspathcmp((*a)->path, (*b)->path);

fspathcmp() reads core.ignorecase from current repo. I guess it's
insane to have this key different between repos on the same machine,
so it should be ok. But I want to point this out just in case I'm
missing something.

> @@ -188,7 +190,7 @@ struct worktree **get_worktrees(unsigned flags)
>                         if (is_dot_or_dotdot(d->d_name))
>                                 continue;
>
> -                       if ((linked = get_linked_worktree(d->d_name))) {
> +                       if ((linked = get_linked_worktree(git_common_dir, d->d_name))) {
>                                 ALLOC_GROW(list, counter + 1, alloc);
>                                 list[counter++] = linked;
>                         }
> @@ -209,6 +211,30 @@ struct worktree **get_worktrees(unsigned flags)
>         return list;

Right before this line is mark_current_worktree(), which in turn calls
get_git_dir() and not suitable for peeking into another repository the
way submodule code does. get_worktree_git_dir() called within that
function shares the same problem.

>  }
>
> +struct worktree **get_worktrees(unsigned flags)
> +{
> +       return get_worktrees_internal(get_git_common_dir(), flags);
> +}
> +
> +struct worktree **get_submodule_worktrees(const char *path, unsigned flags)
> +{
> +       char *submodule_gitdir;
> +       struct strbuf sb = STRBUF_INIT;
> +       struct worktree **ret;
> +
> +       submodule_gitdir = git_pathdup_submodule(path, "%s", "");
> +       if (!submodule_gitdir)
> +               return NULL;
> +
> +       /* the env would be set for the superproject */
> +       get_common_dir_noenv(&sb, submodule_gitdir);

Technically we need to read submodule_gitdir/.config and see if we can
understand core.repositoryformatversion, or find any unrecognized
extensions. But the problem is not specific to this code. And fixing
it is no small task. But perhaps we could call a dummy
validate_submodule_gitdir() here? Then when we implement that function
for real, we don't have to search the entire code base to see where to
put it.

Kinda off-topic though. Feel free to ignore the above comment.

> +       ret = get_worktrees_internal(sb.buf, flags);
> +
> +       strbuf_release(&sb);
> +       free(submodule_gitdir);
> +       return ret;
> +}
-- 
Duy

  reply	other threads:[~2016-12-08 10:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-08  1:46 [PATCHv6 0/7] submodule embedgitdirs Stefan Beller
2016-12-08  1:46 ` [PATCHv6 1/7] submodule: use absolute path for computing relative path connecting Stefan Beller
2016-12-08  9:45   ` Duy Nguyen
2016-12-08  1:46 ` [PATCHv6 2/7] submodule helper: support super prefix Stefan Beller
2016-12-08  9:52   ` Duy Nguyen
2016-12-08 20:19     ` Stefan Beller
2016-12-08  1:46 ` [PATCHv6 3/7] test-lib-functions.sh: teach test_commit -C <dir> Stefan Beller
2016-12-08  1:46 ` [PATCHv6 4/7] worktree: get worktrees from submodules Stefan Beller
2016-12-08 10:09   ` Duy Nguyen [this message]
2016-12-08 18:55     ` Stefan Beller
2016-12-09 12:46       ` Duy Nguyen
2016-12-09 23:00       ` Brandon Williams
2016-12-09 23:10         ` Stefan Beller
2016-12-08  1:46 ` [PATCHv6 5/7] worktree: add function to check if worktrees are in use Stefan Beller
2016-12-08 10:40   ` Duy Nguyen
2016-12-08 10:51     ` Duy Nguyen
2016-12-08 19:32       ` Stefan Beller
2016-12-08  1:46 ` [PATCHv6 6/7] move connect_work_tree_and_git_dir to dir.h Stefan Beller
2016-12-08  1:46 ` [PATCHv6 7/7] submodule: add absorb-git-dir function Stefan Beller
2016-12-08 10:56   ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACsJy8Bs78ywGq5p6yAFGi1KACAXFEeroyQSJye5-RL5gqOS+Q@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).