public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] worktree: reject NULL worktree in get_worktree_git_dir()
Date: Fri, 13 Mar 2026 14:42:07 -0700	[thread overview]
Message-ID: <xmqqfr632yq8.fsf@gitster.g> (raw)
In-Reply-To: <1151b5b302069b4f3414a37e3be4bdbbc7e40686.1773411586.git.phillip.wood@dunelm.org.uk> (Phillip Wood's message of "Fri, 13 Mar 2026 14:19:50 +0000")

Phillip Wood <phillip.wood123@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> This removes the final dependence on "the_repository" in
> get_worktree_git_dir(). The last commit removed only caller that
> passed a NULL worktree.
>
> get_worktree_git_dir() has the following callers:
>
>  - branch.c:prepare_checked_out_branches() which loops over all
>    worktrees.
>
>  - builtin/fsck.c:cmd_fsck() which loops over all worktrees.
>
>  - builtin/receive-pack.c:update_worktree() which is called from
>    update() only when "worktree" is non-NULL.
>
>  - builtin/worktree.c:validate_no_submodules() which is called from
>    check_clean_worktree() and move_worktree(), both of which supply
>    a non-NULL worktree.
>
>  - reachable.c:add_rebase_files() which loops over all worktrees.
>
>  - revision.c:add_index_objects_to_pending() which loops over all
>    worktrees.
>
>  - worktree.c:is_current_worktree() which expects a non-NULL worktree.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  worktree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/worktree.c b/worktree.c
> index 344ad0c031b..1ed5e8c3cd2 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -227,7 +227,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));
> +		BUG("%s() called with NULL worktree", __func__);
>  	else if (!wt->id)
>  		return xstrdup(repo_get_common_dir(wt->repo));
>  	else

<worktree.h> still has

    /*
     * Return git dir of the worktree. Note that the path may be relative.
     * If wt is NULL, git dir of current worktree is returned.
     */
    char *get_worktree_git_dir(const struct worktree *wt);

which needs a matching adjustment.

  reply	other threads:[~2026-03-13 21:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13 14:19 [PATCH 0/3] worktree: stop using "the_repository" in is_current_worktree() Phillip Wood
2026-03-13 14:19 ` [PATCH 1/3] worktree: remove "the_repository" from is_current_worktree() Phillip Wood
2026-03-13 14:19 ` [PATCH 2/3] worktree add: stop reading ".git/HEAD" Phillip Wood
2026-03-13 21:41   ` Junio C Hamano
2026-03-13 14:19 ` [PATCH 3/3] worktree: reject NULL worktree in get_worktree_git_dir() Phillip Wood
2026-03-13 21:42   ` Junio C Hamano [this message]
2026-03-14 20:09     ` Phillip Wood
2026-03-15 16:18 ` [PATCH v2 0/3] worktree: stop using "the_repository" in is_current_worktree() Phillip Wood
2026-03-15 16:18   ` [PATCH v2 1/3] worktree: remove "the_repository" from is_current_worktree() Phillip Wood
2026-03-16  7:38     ` Patrick Steinhardt
2026-03-16 16:22       ` Phillip Wood
2026-03-17 10:24         ` Phillip Wood
2026-03-23  9:41           ` Shreyansh Paliwal
2026-03-23 14:37             ` Phillip Wood
2026-03-23 17:05               ` Shreyansh Paliwal
2026-03-15 16:18   ` [PATCH v2 2/3] worktree add: stop reading ".git/HEAD" Phillip Wood
2026-03-16  7:39     ` Patrick Steinhardt
2026-03-15 16:18   ` [PATCH v2 3/3] worktree: reject NULL worktree in get_worktree_git_dir() Phillip Wood
2026-03-15 21:17   ` [PATCH v2 0/3] worktree: stop using "the_repository" in is_current_worktree() Junio C Hamano
2026-03-26 14:16 ` [PATCH v3 " Phillip Wood
2026-03-26 14:16   ` [PATCH v3 1/3] worktree: remove "the_repository" from is_current_worktree() Phillip Wood
2026-03-26 15:48     ` Junio C Hamano
2026-03-27 16:40       ` Phillip Wood
2026-03-27 17:07         ` Junio C Hamano
2026-03-26 14:16   ` [PATCH v3 2/3] worktree add: stop reading ".git/HEAD" Phillip Wood
2026-03-26 14:16   ` [PATCH v3 3/3] worktree: reject NULL worktree in get_worktree_git_dir() Phillip Wood

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=xmqqfr632yq8.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood123@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox