public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Cc: git@vger.kernel.org,  karthik.188@gmail.com,  phillip.wood123@gmail.com
Subject: Re: [PATCH V2 2/3] wt-status: pass struct repository and wt_status through function parameters
Date: Sat, 07 Feb 2026 22:08:09 -0800	[thread overview]
Message-ID: <xmqq4inrahti.fsf@gitster.g> (raw)
In-Reply-To: <20260208044450.34444-1-shreyanshpaliwalcmsmn@gmail.com> (Shreyansh Paliwal's message of "Sun, 8 Feb 2026 10:14:14 +0530")

Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:

>> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
>> 
>> > -int wt_status_check_rebase(const struct worktree *wt,
>> > -			   struct wt_status_state *state)
>> > +int wt_status_check_rebase(struct repository *r,
>> > +	 			const struct worktree *wt,
>> > +			    struct wt_status_state *state)
>> 
>> Funny indentation.
>
> my bad, will fix it.
>
>> 
>> Besides, should we adding a yet another repository parameter to the
>> function?  The worktree wt knows what repository it belongs to.
>> 
>> > -int wt_status_check_bisect(const struct worktree *wt,
>> > +int wt_status_check_bisect(struct repository *r, 
>> > +			   struct worktree *wt,
>> >  			   struct wt_status_state *state)
>> 
>> Same comment about "r" vs "wt->repo" applies here.
>
> Actually adding another repository parameter to both of these functions
> is needed because of the calls like wt_status_check_rebase(NULL, state)
> and wt_status_check_bisect(NULL, state) from wt_status_get_state().
> In the case where wt is NULL, accessing wt->repo can lead to issues.

But stopping thought at that point is not a reasonable thing to do,
immediately after you notice that wt is sometimes NULL.  It merely
means that unconditionally dereferencing wt->repo without thinking
is not good enough, doesn't it?

And what is the case where worktree is NULL?  What are we doing with
worktree set to NULL?  Is it when secondary worktrees do not come
into the picture at all and you can safely use the_repository?

    ... goes and looks ...

Ahh, I think the real culprit that needs cleaning up is the worktree
API, where they pass NULL to mean "the primary worktree that has its
.git/ directory at its natural place".  So it may not necessarily be
the_repository we are dealing with.  There is *no* such client code
right now, but we could imagine that a program that starts in a
repository visits the primary worktree of another repository and
asks the worktree status there, and once such a client code appears,
we need to be able to say "we are dealing with the primary worktree
for this repository".

In the longer run, I think we should fix the worktree API so that
even for the primary worktree we will always have a non-NULL "struct
worktree" object, perhaps with its .id member set to NULL to signal
that it is the primary worktree, so that we do not have to have this
strange "we must pass repository redundantly even though we are
passing worktree" API elsewhere.  Not just this code you are making
worse, path.c:worktree_git_path() already is a victim of this
misdesign of the worktree API.  It has "if wt is given, then the r
parameter should be the same as wt->repo" nonsense, which we
wouldn't have had to have if we had a worktree object even for the
primary worktree,  Look at how ugly that code is, and weep X-<.

And the same misdesign of the worktree API has caused your [1/3] to
pass 'r' but yet still depend on the_repository, which you had to
fix in [2/3], in this function.

So, I dunno.  If you are ambitious, you may want to clean up the
worktree API before this series.  Alternatively you may be able to
punt on the parts of the wt-status that interact with worktree API,
and move the rest of wt-status less dependent on the_repository, but
I am not sure.

Thanks.

  reply	other threads:[~2026-02-08  6:08 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-31 18:57 [PATCH 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-01-31 18:57 ` [PATCH 1/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-02 10:02   ` Karthik Nayak
2026-02-02 18:42     ` Junio C Hamano
2026-02-02 18:57     ` Shreyansh Paliwal
2026-02-02 22:41       ` Junio C Hamano
2026-02-02 23:03         ` Junio C Hamano
2026-02-03  9:53           ` Shreyansh Paliwal
2026-02-03 11:06             ` Phillip Wood
2026-02-03 15:20               ` Shreyansh Paliwal
2026-02-03 10:58       ` Phillip Wood
2026-02-03 15:15         ` Shreyansh Paliwal
2026-01-31 18:57 ` [PATCH 2/3] wt-status: pass struct repository and wt_status through function parameters Shreyansh Paliwal
2026-01-31 18:57 ` [PATCH 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-02 10:03   ` Karthik Nayak
2026-02-02 19:03     ` Shreyansh Paliwal
2026-02-04 10:18       ` Karthik Nayak
2026-02-04 11:22         ` Shreyansh Paliwal
2026-02-05 10:13 ` [PATCH V2 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-02-05 10:13   ` [PATCH V2 1/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-05 10:59     ` Karthik Nayak
2026-02-05 11:11       ` Karthik Nayak
2026-02-05 12:18         ` Shreyansh Paliwal
2026-02-05 16:08           ` Phillip Wood
2026-02-05 17:41             ` Shreyansh Paliwal
2026-02-05 10:13   ` [PATCH V2 2/3] wt-status: pass struct repository and wt_status through function parameters Shreyansh Paliwal
2026-02-05 11:09     ` Karthik Nayak
2026-02-05 12:04       ` Shreyansh Paliwal
2026-02-06  9:24         ` Karthik Nayak
2026-02-06  9:32           ` Shreyansh Paliwal
2026-02-06 12:57             ` Shreyansh Paliwal
2026-02-06 14:54               ` Phillip Wood
2026-02-06 17:06                 ` Shreyansh Paliwal
2026-02-05 15:58       ` Phillip Wood
2026-02-05 10:13   ` [PATCH V2 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-05 10:27   ` [PATCH V2 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-02-05 15:53     ` Phillip Wood
2026-02-05 17:39       ` Shreyansh Paliwal
2026-02-05 18:02         ` Kristoffer Haugsbakk
2026-02-05 18:18           ` Shreyansh Paliwal
2026-02-07 10:00   ` [PATCH v3 " Shreyansh Paliwal
2026-02-07 10:00     ` [PATCH v3 1/3] wt-status: pass struct repository through function parameters Shreyansh Paliwal
2026-02-08  1:14       ` Junio C Hamano
2026-02-08  4:55         ` [PATCH V2 2/3] wt-status: pass struct repository and wt_status " Shreyansh Paliwal
2026-02-09  8:36         ` [PATCH v3 1/3] wt-status: pass struct repository " Karthik Nayak
2026-02-08  1:21       ` Junio C Hamano
2026-02-08  4:44         ` [PATCH V2 2/3] wt-status: pass struct repository and wt_status " Shreyansh Paliwal
2026-02-08  6:08           ` Junio C Hamano [this message]
2026-02-08 15:25             ` Shreyansh Paliwal
2026-02-09  9:02               ` Karthik Nayak
2026-02-09 13:43                 ` Shreyansh Paliwal
2026-02-09 16:13                 ` Junio C Hamano
2026-02-10  9:50                   ` Karthik Nayak
2026-02-07 10:00     ` [PATCH v3 2/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-07 10:00     ` [PATCH v3 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-17 17:29 ` [PATCH v4 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-02-17 17:29   ` [PATCH v4 1/3] wt-status: pass struct repository through function parameters Shreyansh Paliwal
2026-02-17 17:29   ` [PATCH v4 2/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-17 17:29   ` [PATCH v4 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-18 16:13   ` [PATCH v4 0/3] wt-status: reduce reliance on global state Phillip Wood
2026-02-18 16:48     ` Shreyansh Paliwal
2026-02-18 17:53 ` [PATCH v5 " Shreyansh Paliwal
2026-02-18 17:53   ` [PATCH v5 1/3] wt-status: pass struct repository through function parameters Shreyansh Paliwal
2026-02-18 17:53   ` [PATCH v5 2/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-18 17:53   ` [PATCH v5 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-03-06 22:31   ` [PATCH v5 0/3] wt-status: reduce reliance on global state Junio C Hamano
2026-03-09 10:32     ` Karthik Nayak
2026-03-09 18:30       ` Junio C Hamano
2026-03-09 10:35     ` 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=xmqq4inrahti.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=phillip.wood123@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox