From: Junio C Hamano <gitster@pobox.com>
To: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Cc: git@vger.kernel.org, karthik.188@gmail.com
Subject: Re: [RFC][PATCH 1/2] worktree: represent the primary worktree with '/' instead of NULL
Date: Fri, 13 Feb 2026 13:35:32 -0800 [thread overview]
Message-ID: <xmqq7bsgl42j.fsf@gitster.g> (raw)
In-Reply-To: <20260213120529.15475-2-shreyanshpaliwalcmsmn@gmail.com> (Shreyansh Paliwal's message of "Fri, 13 Feb 2026 17:29:53 +0530")
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
> diff --git a/worktree.c b/worktree.c
> index 9308389cb6..b29934407f 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -101,6 +101,7 @@ static struct worktree *get_main_worktree(int skip_reading_head)
>
> CALLOC_ARRAY(worktree, 1);
> worktree->repo = the_repository;
> + worktree->id = xstrdup("/");
> worktree->path = strbuf_detach(&worktree_path, NULL);
> worktree->is_current = is_current_worktree(worktree);
> worktree->is_bare = (is_bare_repository_cfg == 1) ||
Presumably we left .id = NULL from CALLOC_ARRAY(), so this looks
sensible. When releasing resources from an instance of worktree,
we'd blindly free(worktree->id) and in the old world, free(NULL)
turned into no-op, and this xstrdup()'d copy will be freed in the
new world, so there is nothing funny here, I hope? This one, and
the change to is_main_worktree() go together.
> @@ -127,6 +128,8 @@ struct worktree *get_linked_worktree(const char *id,
>
> if (!id)
> die("Missing linked worktree name");
> + if (!strcmp(id, "/"))
> + die("'/' is reserved for primary worktree");
Makes me wonder if this is a BUG not die; where does id come from?
... goes and looks ...
The only caller is worktree.c:get_worktrees_internal() and it is
feeding d->d_name that came from readdir_skip_dot_and_dotdot(), so
it cannot be "/".
By the way, I suspect that get_linked_worktree() should become
file-scope static, as there is no other caller.
> @@ -206,9 +209,7 @@ struct worktree **get_worktrees_without_reading_head(void)
>
> char *get_worktree_git_dir(const struct worktree *wt)
> {
> - if (!wt)
> - return xstrdup(repo_get_git_dir(the_repository));
> - else if (!wt->id)
> + if (is_main_worktree(wt))
> return xstrdup(repo_get_common_dir(the_repository));
> else
> return repo_common_path(the_repository, "worktrees/%s", wt->id);
Good spotting. This series needs to spot any and all places that
use these other conventions (i.e. wt->id == NULL) to identify the
primary worktree and rewrite them to call is_main_worktree(), which
may be a chore, but once it is done, it would become a lot easier to
follow the resulting code.
> @@ -277,7 +278,7 @@ struct worktree *find_worktree_by_path(struct worktree **list, const char *p)
>
> int is_main_worktree(const struct worktree *wt)
> {
> - return !wt->id;
> + return !strcmp(wt->id, "/");
> }
OK.
> @@ -566,7 +567,7 @@ void strbuf_worktree_ref(const struct worktree *wt,
> {
> if (parse_worktree_ref(refname, NULL, NULL, NULL) ==
> REF_WORKTREE_CURRENT &&
> - wt && !wt->is_current) {
> + !wt->is_current) {
OK.
> @@ -629,6 +630,9 @@ static void repair_gitfile(struct worktree *wt,
> char *path = NULL;
> int err;
>
> + if (is_main_worktree(wt))
> + goto done;
This is a bit new.
The original did not say
if (!wt || !wt->id || !strcmp(wt->id, "/"))
goto done;
The only caller is iterating over the resulting list of worktrees
returned from get_worktrees_internal(1) *BUT* it already skips the
primary worktree (the function MUST return the primary one as the
first one, and the callers MUST be aware of the convention).
So I am not sure if the new check is even needed. Or rather, this ...
if (!wt || !wt->id || !strcmp(wt->id, "/"))
BUG("why are you feeding me the primary worktree???");
... might be more appropriate, perhaps? I dunno.
> /* missing worktree can't be repaired */
> if (!file_exists(wt->path))
> goto done;
next prev parent reply other threads:[~2026-02-13 21:35 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 [this message]
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
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=xmqq7bsgl42j.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=shreyanshpaliwalcmsmn@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.