From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: git@vger.kernel.org,
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>,
Eric Sunshine <sunshine@sunshineco.com>,
Karthik Nayak <karthik.188@gmail.com>
Subject: Re: [PATCH v2 1/2] wt-status: avoid passing NULL worktree
Date: Thu, 19 Feb 2026 11:30:10 -0800 [thread overview]
Message-ID: <xmqqv7fs4jlp.fsf@gitster.g> (raw)
In-Reply-To: <902295b87146e5cb5358cebab51f8d66701290a8.1771511192.git.phillip.wood@dunelm.org.uk> (Phillip Wood's message of "Thu, 19 Feb 2026 14:26:32 +0000")
Phillip Wood <phillip.wood123@gmail.com> writes:
> In general the "struct worktree" returned may not correspond to
> the "current" worktree defined by is_current_worktree() as that
> function uses "the_repository" rather than "wt->repo" when
> deciding which worktree is "current". In practice the "struct
> repository" we pass corresponds to "the_repository" as we only
> ever operate on a single repository at the moment.
This may technically be a correct description, but feels very
unsatisfactory, as it fails to answer this very simple question:
what does it mean when is_current_worktree() says "no" to the
worktree instance returned by this function? In other words,
what are the sample sequences that can lead to such a worktree?
We start a Git process in a directory which is part of a set of
worktrees governed by a single repository. That repository becomes
the_repository and the worktree instance that represents our
directory would satisfy is_current_worktree(). Then we visit
another directory that is one of a set of worktrees goverend by a
separate and different repository. We now have a repository
instance that is different from our the_repository. Perhaps our
in-core submodule code may do that, and that different repository is
the submodule in question. Running this function will yield the
worktree instance, whose path is a subdirectory of our current
directory where the submodule is checked out? It may be the current
worktree if we asked is_current_worktree() about that worktree in
the context of the submodule, but it is not in the context of our
superproject repository. In fact, none of the worktrees governed by
the submodule repository can be "current", as they are not our
checkout, from the viewpoint of our superproject repository.
Is that what is going on here?
A related question that is much more relevant is this:
What is the significance of the worktree, relative to our
process, returned by this function for a given repo? What is so
special about this worktree, among others that are also linked
to the same repository?
What does it mean for a worktree to "corresponds to"
repo->{gitdir,worktree}? Why does the currently running Git
process want to grab such a worktree?
If the answer were "it is the current worktree", then we would have
a nice and very understandable name "get-current-worktree-for-repo"
for the function, but because I do not think of a good answer to the
question (and you already explained why it is not the "current"
worktree), I cannot improve on "get _A_ worktree from repository",
the name given by the patch, which leaves the "which one of the
worktrees are we talking about? Why did we pick that particular one
instead of other ones" unanswered.
Or perhaps "the current worktree" is not a per-Git-process concept,
but is a per-process-per-repo concept?
In other words, the function is_current_worktree(wt) may not take a
repository and always compute things relative to the_repository, but
once we wean ourselves off of the_repository, we would/should have
repo_is_current_worktree(repo, wt), making is_current_worktree(wt) a
thin wrapper for repo_is_current_worktree(the_repository, wt)?
> diff --git a/worktree.h b/worktree.h
> index e4bcccdc0ae..06efe26b835 100644
> --- a/worktree.h
> +++ b/worktree.h
> @@ -38,6 +38,12 @@ struct worktree **get_worktrees(void);
> */
> struct worktree **get_worktrees_without_reading_head(void);
>
> +/*
> + * Construct a struct worktree corresponding to repo->gitdir and
> + * repo->worktree.
> + */
> +struct worktree *get_worktree_from_repository(struct repository *repo);
> +
next prev parent reply other threads:[~2026-02-19 19:30 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-13 11:59 [RFC][PATCH 0/2] worktree: change representation and usage of primary worktree Shreyansh Paliwal
2026-02-13 11:59 ` [RFC][PATCH 1/2] worktree: represent the primary worktree with '/' instead of NULL Shreyansh Paliwal
2026-02-13 21:35 ` Junio C Hamano
2026-02-14 9:54 ` Shreyansh Paliwal
2026-02-13 11:59 ` [RFC][PATCH 2/2] worktree: stop passing NULL as primary worktree Shreyansh Paliwal
2026-02-13 22:29 ` Junio C Hamano
2026-02-14 9:59 ` Shreyansh Paliwal
2026-02-14 14:30 ` Phillip Wood
2026-02-14 15:34 ` Junio C Hamano
2026-02-15 8:56 ` Shreyansh Paliwal
2026-02-16 16:18 ` Phillip Wood
2026-02-17 5:21 ` Junio C Hamano
2026-02-17 10:09 ` Shreyansh Paliwal
2026-02-16 16:18 ` [PATCH 0/2] worktree_git_path(): remove repository argument Phillip Wood
2026-02-16 16:18 ` [PATCH 1/2] wt-status: avoid passing NULL worktree Phillip Wood
2026-02-17 9:23 ` Phillip Wood
2026-02-17 10:18 ` Shreyansh Paliwal
2026-02-17 15:20 ` Phillip Wood
2026-02-17 16:38 ` Shreyansh Paliwal
2026-02-17 18:29 ` Junio C Hamano
2026-02-17 17:46 ` Karthik Nayak
2026-02-18 14:19 ` Phillip Wood
2026-02-17 18:47 ` Junio C Hamano
2026-02-18 14:18 ` Phillip Wood
2026-02-16 16:18 ` [PATCH 2/2] path: remove repository argument from worktree_git_path() Phillip Wood
2026-02-17 17:48 ` Karthik Nayak
2026-02-17 10:12 ` [PATCH 0/2] worktree_git_path(): remove repository argument Shreyansh Paliwal
2026-02-17 15:22 ` Phillip Wood
2026-02-17 16:45 ` Shreyansh Paliwal
2026-02-19 14:26 ` [PATCH v2 " Phillip Wood
2026-02-19 14:26 ` [PATCH v2 1/2] wt-status: avoid passing NULL worktree Phillip Wood
2026-02-19 19:30 ` Junio C Hamano [this message]
2026-02-19 20:37 ` Junio C Hamano
2026-02-25 16:39 ` Phillip Wood
2026-02-25 17:11 ` Junio C Hamano
2026-02-26 16:09 ` Phillip Wood
2026-02-26 16:15 ` Junio C Hamano
2026-02-19 14:26 ` [PATCH v2 2/2] path: remove repository argument from worktree_git_path() Phillip Wood
2026-02-19 19:34 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqv7fs4jlp.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=shreyanshpaliwalcmsmn@gmail.com \
--cc=sunshine@sunshineco.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox