public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Phillip Wood <phillip.wood@dunelm.org.uk>, 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: Re: [PATCH 1/2] wt-status: avoid passing NULL worktree
Date: Tue, 17 Feb 2026 09:23:04 +0000	[thread overview]
Message-ID: <89c78ce2-1783-416d-9ae5-ef51f6bde58d@gmail.com> (raw)
In-Reply-To: <409871a7d521b76c9eb811d3c49747e04de8defc.1771258688.git.phillip.wood@dunelm.org.uk>

On 16/02/2026 16:18, Phillip Wood wrote:
> 
> +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);
> +	wt->is_bare = !!repo->worktree;
> +	if (fspathcmp(gitdir, commondir))
> +		wt->id = xstrdup(find_last_dir_sep(commondir) + 1);

Oops s/commondir/gitdir/ - I'll wait to see if there are any other 
comments before re-rolling (perhaps with a test that runs git status on 
a rebase in a linked worktree)

Thanks

Phillip

> +	wt->is_current = is_current_worktree(wt);
> +	add_head_info(wt);
> +
> +	free(gitdir);
> +	free(commondir);
> +	return wt;
> +}
> +
>   /*
>   * When in a secondary worktree, and when extensions.worktreeConfig
>   * is true, only $commondir/config and $commondir/worktrees/<id>/
> diff --git a/worktree.h b/worktree.h
> index e4bcccdc0ae..b162bbabd50 100644
> --- a/worktree.h
> +++ b/worktree.h
> @@ -38,7 +38,10 @@ struct worktree **get_worktrees(void);
>    */
>   struct worktree **get_worktrees_without_reading_head(void);
>   
> -/*
> +/* Construct a struct worktree from a struct repository */
> +struct worktree *get_worktree_from_repository(struct repository *repo);
> +
> + /*
>    * Returns 1 if linked worktrees exist, 0 otherwise.
>    */
>   int submodule_uses_worktrees(const char *path);
> diff --git a/wt-status.c b/wt-status.c
> index 95942399f8c..2debda534c1 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1747,6 +1747,9 @@ int wt_status_check_rebase(const struct worktree *wt,
>   {
>   	struct stat st;
>   
> +	if (!wt)
> +		BUG("wt_status_check_rebase() called with NULL worktree");
> +
>   	if (!stat(worktree_git_path(the_repository, wt, "rebase-apply"), &st)) {
>   		if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/applying"), &st)) {
>   			state->am_in_progress = 1;
> @@ -1774,6 +1777,9 @@ int wt_status_check_bisect(const struct worktree *wt,
>   {
>   	struct stat st;
>   
> +	if (!wt)
> +		BUG("wt_status_check_bisect() called with NULL worktree");
> +
>   	if (!stat(worktree_git_path(the_repository, wt, "BISECT_LOG"), &st)) {
>   		state->bisect_in_progress = 1;
>   		state->bisecting_from = get_branch(wt, "BISECT_START");
> @@ -1819,18 +1825,19 @@ void wt_status_get_state(struct repository *r,
>   	struct stat st;
>   	struct object_id oid;
>   	enum replay_action action;
> +	struct worktree *wt = get_worktree_from_repository(r);
>   
>   	if (!stat(git_path_merge_head(r), &st)) {
> -		wt_status_check_rebase(NULL, state);
> +		wt_status_check_rebase(wt, state);
>   		state->merge_in_progress = 1;
> -	} else if (wt_status_check_rebase(NULL, state)) {
> +	} else if (wt_status_check_rebase(wt, state)) {
>   		;		/* all set */
>   	} else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
>   		   !repo_get_oid(r, "CHERRY_PICK_HEAD", &oid)) {
>   		state->cherry_pick_in_progress = 1;
>   		oidcpy(&state->cherry_pick_head_oid, &oid);
>   	}
> -	wt_status_check_bisect(NULL, state);
> +	wt_status_check_bisect(wt, state);
>   	if (refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD") &&
>   	    !repo_get_oid(r, "REVERT_HEAD", &oid)) {
>   		state->revert_in_progress = 1;
> @@ -1848,6 +1855,8 @@ void wt_status_get_state(struct repository *r,
>   	if (get_detached_from)
>   		wt_status_get_detached_from(r, state);
>   	wt_status_check_sparse_checkout(r, state);
> +
> +	free_worktree(wt);
>   }
>   
>   static void wt_longstatus_print_state(struct wt_status *s)


  reply	other threads:[~2026-02-17  9:23 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 [this message]
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=89c78ce2-1783-416d-9ae5-ef51f6bde58d@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