From: Phillip Wood <phillip.wood123@gmail.com>
To: "Rubén Justo" <rjusto@gmail.com>, "Junio C Hamano" <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>, Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH] worktree: teach find_shared_symref to ignore current worktree
Date: Thu, 19 Jan 2023 10:48:27 +0000 [thread overview]
Message-ID: <cedc93ec-aa6f-65bf-65be-0dca3d4d0186@dunelm.org.uk> (raw)
In-Reply-To: <f209958f-e824-181b-f9d5-6e4bc8e53646@gmail.com>
Hi Rubén
On 18/01/2023 23:50, Rubén Justo wrote:
> On 17-ene-2023 15:27:29, Junio C Hamano wrote:
>
>> being solved. Rather, it is unclear what problem you are solving.
>
> Sorry, I didn't explain the motivation well in the message.
I'm afraid I'm still not totally clear from this message exactly what
the problem is. Having looked at die_if_checked_out() I think it maybe
the second of Junio's options
- If the current branch the the current worktree is checked out in
a different worktree, we get the current worktree back.
Here is the function:
void die_if_checked_out(const char *branch, int ignore_current_worktree)
{
struct worktree **worktrees = get_worktrees();
const struct worktree *wt;
wt = find_shared_symref(worktrees, "HEAD", branch);
if (wt && (!ignore_current_worktree || !wt->is_current)) {
skip_prefix(branch, "refs/heads/", &branch);
die(_("'%s' is already checked out at '%s'"), branch, wt->path);
}
free_worktrees(worktrees);
}
It takes a flag to ignore the current worktree but uses
find_shared_symref() which does not have such a flag to see if the
branch is checked out. This means that if a branch is checkout out twice
find_shared_symref() may return the current worktree rather than the one
we're interested in.
If that is the problem you're trying to solve I think it would be better
to keep the signature of find_shared_symref() the same and add a helper
function that is called by die_if_checked_out() and find_shared_symref()
which can optionally ignore the current worktree. The commit message for
such a patch should explain you're fixing a bug rather than trying to
change the existing behavior.
Best Wishes
Phillip
> First, I'm not sure if "ignore_current_worktree" is correct, maybe needs
> to be "prefer_current_worktree". Having said that, let me use an example.
>
> With...
>
> $ git worktree add wt1 -b main
> $ git worktree add wt2 -f main
>
> ... we get confuse results:
>
> $ git -C wt1 rebase main main
> Current branch main is up to date.
> $ git -C wt2 rebase main main
> fatal: 'main' is already checked out...
>
> The problem I'm trying to solve is that find_shared_symref() returns the
> first matching worktree, and a possible matching "current worktree"
> might not be the first matching one. That's why die_if_checked_out()
> dies with "git -C wt2".
>
> find_shared_symref() searches through the list of worktrees that
> get_worktrees() composes: first the main worktree and then, as getdir()
> returns them, those in .git/worktrees/*. The search is sequential and
> once a match is found, it is returned. And so die_if_checked_out(),
> when asked to "ignore_current_worktree", is going to consider for
> "is_current" the worktree which may or may not be the "current" one,
> depending on the sequence from get_worktree(), and getdir() ultimately.
>
> If we want to disallow operations on a worktree with a checked out
> branch also on another worktree, we need the "ignore_current_worktree".
> But, and now I'm more in favor of this, if we prefer to allow the
> operation, we need a "prefer_current_worktree", to induce
> find_shared_symref() to return the "current" one if it matches, or any
> other one that matches.
next prev parent reply other threads:[~2023-01-19 10:49 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 0:36 [PATCH] worktree: teach find_shared_symref to ignore current worktree Rubén Justo
2023-01-17 23:27 ` Junio C Hamano
2023-01-18 23:50 ` Rubén Justo
2023-01-19 10:48 ` Phillip Wood [this message]
2023-01-19 23:18 ` Rubén Justo
2023-01-22 1:20 ` [PATCH v2 0/3] fix die_if_checked_out() when ignore_current_worktree Rubén Justo
2023-01-22 1:23 ` [PATCH v2 1/3] branch: " Rubén Justo
2023-01-22 1:50 ` Junio C Hamano
2023-01-22 11:51 ` Rubén Justo
2023-01-22 19:58 ` Junio C Hamano
2023-01-22 23:21 ` Rubén Justo
2023-01-24 10:35 ` Phillip Wood
2023-01-26 3:07 ` Rubén Justo
2023-01-22 1:28 ` [PATCH v2 2/3] rebase: refuse to switch to a branch already checked out elsewhere (test) Rubén Justo
2023-01-22 1:28 ` [PATCH v2 3/3] switch: reject if the branch is " Rubén Justo
2023-02-04 23:19 ` [PATCH v3 0/4] fix die_if_checked_out() when ignore_current_worktree Rubén Justo
2023-02-04 23:25 ` [PATCH v3 1/4] worktree: introduce is_shared_symref() Rubén Justo
2023-02-07 10:44 ` Phillip Wood
2023-02-04 23:25 ` [PATCH v3 2/4] branch: fix die_if_checked_out() when ignore_current_worktree Rubén Justo
2023-02-06 16:56 ` Ævar Arnfjörð Bjarmason
2023-02-06 23:09 ` Rubén Justo
2023-02-07 10:50 ` Phillip Wood
2023-02-07 12:58 ` Ævar Arnfjörð Bjarmason
2023-02-04 23:26 ` [PATCH v3 3/4] rebase: refuse to switch to a branch already checked out elsewhere (test) Rubén Justo
2023-02-06 16:59 ` Ævar Arnfjörð Bjarmason
2023-02-06 23:16 ` Rubén Justo
2023-02-07 10:52 ` Phillip Wood
2023-02-08 0:43 ` Rubén Justo
2023-02-08 5:19 ` Junio C Hamano
2023-02-08 22:09 ` Rubén Justo
2023-02-04 23:26 ` [PATCH v3 4/4] switch: reject if the branch is " Rubén Justo
2023-02-15 4:17 ` Eric Sunshine
2023-02-15 22:17 ` Rubén Justo
2023-02-25 14:14 ` [PATCH v4 0/4] fix die_if_checked_out() when ignore_current_worktree Rubén Justo
2023-02-25 14:21 ` [PATCH v4 1/4] worktree: introduce is_shared_symref() Rubén Justo
2023-02-25 14:22 ` [PATCH v4 2/4] branch: fix die_if_checked_out() when ignore_current_worktree Rubén Justo
2023-02-25 14:22 ` [PATCH v4 3/4] rebase: refuse to switch to a branch already checked out elsewhere (test) Rubén Justo
2023-02-25 14:22 ` [PATCH v4 4/4] switch: reject if the branch is " Rubén Justo
2023-02-25 22:50 ` [PATCH v4 0/4] fix die_if_checked_out() when ignore_current_worktree Junio C Hamano
2023-02-27 0:00 ` Rubén Justo
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cedc93ec-aa6f-65bf-65be-0dca3d4d0186@dunelm.org.uk \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=rjusto@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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).