public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Junio C Hamano <gitster@pobox.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 1/2] wt-status: avoid passing NULL worktree
Date: Wed, 18 Feb 2026 14:18:50 +0000	[thread overview]
Message-ID: <f03fa5a8-b408-4b4e-a254-b0a39b87e636@gmail.com> (raw)
In-Reply-To: <xmqqa4x7cile.fsf@gitster.g>

On 17/02/2026 18:47, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> In preparation for removing the repository argument from
>> worktree_git_path() add a function to construct a "struct worktree"
>> from a "struct repository" and use that to avoid passing a NULL
>> worktree to wt_status_check_bisect() and wt_status_check_rebase().
> 
> Hmph, I am afraid that
> 
>      "Construct a struct worktree from a struct repository"
> 
> is not quite sufficient.  A repository can have more than one
> worktrees, so if you give a repository as a parameter, there needs a
> way for the implementation of this helper function to identify which
> one of them to construct a struct worktree for, and more importantly
> for you as the caller to be able to expect which one the implementation
> would pick, and what that particular worktree among many _means_ to you.
> 
> I know that the implementation uses repo->worktree but what does
> that path mean in the world-view of the worktree API set?

While a repository can have multiple worktrees, a "struct repository" 
points to a particular worktree within that repository via the gitdir 
and worktree members. I'll try and make it clearer that the function 
returns a struct worktree corresponding to those members.

> I am guessing that it is what the worktree API calls "current", but
> if so, perhaps the function should be explained with that word in
> it, and the function name should also contain that word, no?

That's what I thought initially. However is_current_worktree() is 
defined in terms of "the_repository" rather than "wt->repo". That means 
all the struct worktrees within a single process agree on the "current" 
worktree but it is suprising that if "wt->path" matches 
"wt->repo->worktree" it is not necessarily the "current" worktree. I'm 
not sure if we want to change the definition of is_current_worktree() to 
use "wt->repo" rather than "the_repository", but if we do I think we can 
do that separately.

>> +struct worktree *get_worktree_from_repository(struct repository *repo)
>> +{
>> +	struct worktree *wt = xcalloc(1, sizeof(*wt));
>> +	char *gitdir = absolute_pathdup(repo->gitdir);
>> +	char *commondir = absolute_pathdup(repo->commondir);
>> +
>> +	wt->repo = repo;
>> +	if (repo->worktree)
>> +		wt->path = absolute_pathdup(repo->worktree);
> 
> So, if the repository instance knows where the worktree is, we use
> that to wt->path.  Otherwise wt->path is left NULL.

That's actually a bug, we should be using repo->gitdir when the 
repository is bare.

>> +	wt->is_bare = !!repo->worktree;
> 
> I may be confused but don't we have one ! too many?  If we have a
> worktree directory, "git checkout" would check the files there, and
> that is not quite a "bare" repository, no?

Yes, it should be "wt->is_bare = !repo->worktree;"

>> +	if (fspathcmp(gitdir, commondir))
>> +		wt->id = xstrdup(find_last_dir_sep(commondir) + 1);
> 
> OK.  So gitdir and commondir would be the same for the primary and
> for everybody else we'd have "id" as the last directory component of
> the commondir.
> 
>> +	wt->is_current = is_current_worktree(wt);
> 
> Oh, so I guessed wrong and this is not about "current" worktree?
> What does the directory pointed at by repo->worktree mean to the
> callers of this function?  I somehow thought that is_current would
> be always 1 here,.

As explained above "repo->worktree" means nothing to 
is_current_worktree() because it uses "the_repository" instead of 
"wt->repo".

I'll re-roll with the fixes above and a bit more detail in the commit 
message about is_current_worktree() and the that the "struct worktree" 
instance corresponds to worktree that uses repo->gitdir

Thanks

Phillip


  reply	other threads:[~2026-02-18 14:18 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 [this message]
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
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=f03fa5a8-b408-4b4e-a254-b0a39b87e636@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --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