From: Phillip Wood <phillip.wood123@gmail.com>
To: git@vger.kernel.org
Cc: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Eric Sunshine <sunshine@sunshineco.com>,
Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH v2 0/2] worktree_git_path(): remove repository argument
Date: Thu, 19 Feb 2026 14:26:31 +0000 [thread overview]
Message-ID: <cover.1771511192.git.phillip.wood@dunelm.org.uk> (raw)
In-Reply-To: <cover.1771258688.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>
These patches remove the repository argument from worktree_git_path()
in favor of using the repository in the "sturct worktree" argument.
This enables us to remove some uses of "the_repository". The first
patch adds a new function git_worktree_from_repository() to construct
a "struct worktree" based on the repository's worktree and uses it
to avoid passing a NULL worktree to worktree_git_path(). The second
patch then removes the repository argument from that function and
always uses the repository in the worktree argument instead.
Thanks to Karthik and Junio for their comments, here are the changes
since V1:
- always set worktree path - for bare repositories the worktree path
is repo->gitdir
- fix the worktree bareness (there were too many negations)
- fix the wortkree id (it comes from repo->gitdir not repo->commondir)
- add a test for "git status" on a rebase in a linked worktree.
- expand the commit message to explain
(a) that we use the "gitdir" and "worktree" members of "struct
repository" to construct the "struct worktree"
(b) how the "current" worktree is determined
Base-Commit: 852829b3dd2fe4e7c7fc4d8badde644cf1b66c74
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fget-current-worktree%2Fv2
View-Changes-At: https://github.com/phillipwood/git/compare/852829b3d...db9d519cb
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/get-current-worktree/v2
Phillip Wood (2):
wt-status: avoid passing NULL worktree
path: remove repository argument from worktree_git_path()
builtin/fsck.c | 2 +-
builtin/worktree.c | 4 ++--
path.c | 9 ++++-----
path.h | 8 +++-----
revision.c | 2 +-
t/t7512-status-help.sh | 9 +++++++++
worktree.c | 22 +++++++++++++++++++++-
worktree.h | 6 ++++++
wt-status.c | 29 +++++++++++++++++++----------
9 files changed, 66 insertions(+), 25 deletions(-)
Range-diff against v1:
1: 409871a7d52 ! 1: 902295b8714 wt-status: avoid passing NULL worktree
@@ Commit message
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().
+ from a "struct repository" using its "gitdir" and "worktree"
+ members. This function is then used to avoid passing a NULL worktree to
+ wt_status_check_bisect() and wt_status_check_rebase(). 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.
wt_status_check_bisect() and wt_status_check_rebase() have the following
callers:
@@ Commit message
NULL worktree by this patch.
This updates the only callers that pass a NULL worktree to
- worktree_git_path().
+ worktree_git_path(). A new test is added to check that "git status"
+ detects a rebase in a linked worktree.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
+ ## t/t7512-status-help.sh ##
+@@ t/t7512-status-help.sh: EOF
+ test_cmp expected actual
+ '
+
++test_expect_success 'rebase in a linked worktree' '
++ test_might_fail git rebase --abort &&
++ git worktree add wt &&
++ test_when_finished "test_might_fail git -C wt rebase --abort;
++ git worktree remove wt" &&
++ GIT_SEQUENCE_EDITOR="echo break >" git -C wt rebase -i HEAD &&
++ git -C wt status >actual &&
++ test_grep "interactive rebase in progress" actual
++'
+
+ test_expect_success 'prepare am_session' '
+ git reset --hard main &&
+
## worktree.c ##
@@ worktree.c: static int is_current_worktree(struct worktree *wt)
return is_current;
@@ worktree.c: static int is_current_worktree(struct worktree *wt)
+ char *commondir = absolute_pathdup(repo->commondir);
+
+ wt->repo = repo;
-+ if (repo->worktree)
-+ wt->path = absolute_pathdup(repo->worktree);
-+ wt->is_bare = !!repo->worktree;
++ wt->path = absolute_pathdup(repo->worktree ? repo->worktree
++ : repo->gitdir);
++ wt->is_bare = !repo->worktree;
+ if (fspathcmp(gitdir, commondir))
-+ wt->id = xstrdup(find_last_dir_sep(commondir) + 1);
++ wt->id = xstrdup(find_last_dir_sep(gitdir) + 1);
+ wt->is_current = is_current_worktree(wt);
+ add_head_info(wt);
+
@@ worktree.h: struct worktree **get_worktrees(void);
*/
struct worktree **get_worktrees_without_reading_head(void);
--/*
-+/* Construct a struct worktree from a struct repository */
++/*
++ * Construct a struct worktree corresponding to repo->gitdir and
++ * repo->worktree.
++ */
+struct worktree *get_worktree_from_repository(struct repository *repo);
+
-+ /*
+ /*
* Returns 1 if linked worktrees exist, 0 otherwise.
*/
- int submodule_uses_worktrees(const char *path);
## wt-status.c ##
@@ wt-status.c: int wt_status_check_rebase(const struct worktree *wt,
2: 23b8a355b41 = 2: db9d519cbda path: remove repository argument from worktree_git_path()
--
2.52.0.362.g884e03848a9
next prev parent reply other threads:[~2026-02-19 14:26 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 ` Phillip Wood [this message]
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=cover.1771511192.git.phillip.wood@dunelm.org.uk \
--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