From: Junio C Hamano <gitster@pobox.com>
To: Caleb White <cdwhite3@pm.me>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 0/2] Ensure unique worktree ids across repositories
Date: Sun, 01 Dec 2024 13:38:10 +0900 [thread overview]
Message-ID: <xmqq34j8m30t.fsf@gitster.g> (raw)
In-Reply-To: <D5YCFP1AV64F.36B116IUDDEE2@pm.me> (Caleb White's message of "Fri, 29 Nov 2024 03:31:09 +0000")
Caleb White <cdwhite3@pm.me> writes:
> On Thu Nov 28, 2024 at 9:14 PM CST, Junio C Hamano wrote:
>> Caleb White <cdwhite3@pm.me> writes:
>>
>>> The `es/worktree-repair-copied` topic added support for repairing a
>>> worktree from a copy scenario. I noted[1,2] that the topic added the
>>> ability for a repository to "take over" a worktree from another
>>> repository if the worktree_id matched a worktree inside the current
>>> repository which can happen if two repositories use the same worktree name.
>>
>> Problem worth solving. Another would be to fail if the worktree ID
>> proposed to be used is already in use, but the ID is supposed to be
>> almost invisible (unless the user is doing some adiministrative work
>> on the repository), generating a unique ID is a good approach.
>
> There's already a `while` loop that tries incrementing the proposed id
> (e.g., `develop1` if `develop` is taken). However, this is on
> a per-repository basis, so there's no way to know what's already in use
> in another repository.
Usually repositories on a single host are not aware of each other,
so I am not sure if it is a sensible goal to begin with, to try to
ensure a worktree ID is unique "across repositories".
> The problem arises when trying to run `worktree
> repair` on a worktree that has a matching id (like `develop`) from
> another repository. The goal here is that the same worktree name can be
> created in different repositories and the id will be (effectively)
> unique.
OK, but wouldn't that change the problem we need to solve greatly?
The problem is very much simplified, in fact. When we are adding to
.git/worktrees/ of a single repository, we need a unique worktree ID
given to the new worktree. And the ID like `develop` taken from
another repository may or may not be already in use here.
In a repository, a directory ../foo/develop may already be
registered as its worktree, and the user may try to add yet another
directory ../bar/develop as a new worktree. The first one has been
using 'develop' as its ID, and the "worktree add" command to create
the new one needs to tweak the basename 'develop' to make it unique
within this single repository. Shouldn't `repair` that tries to
bring in an orphaned worktree that used to be given a worktree ID by
a potentially different repository (or it could be initially created
in this repository and then forgotten, and in the meantime there
could have been many iterations of `develop` worktrees created for
the repository and while it was missing, its ID plus serial number
may have already taken) follow the same pattern? Whatever worktree
ID that the other repository gave it is invalid in the context of
this repository, anyway.
So I am not sure why we need to complicate the system by adding
random number, which does not help in ensuring uniqueness (it may
make it less likely to collide, but that is different from
guaranteeing uniqueness), while misleading readers that somehow
these numbers after the worktree IDs are serving some purpose.
Am I missing something?
Thanks.
next prev parent reply other threads:[~2024-12-01 4:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 2:44 [PATCH 0/2] Ensure unique worktree ids across repositories Caleb White
2024-11-29 2:44 ` [PATCH 1/2] worktree: add worktree with unique suffix Caleb White
2024-11-29 2:44 ` [PATCH 2/2] worktree: rename worktree id during worktree move Caleb White
2024-11-29 2:49 ` [PATCH 0/2] Ensure unique worktree ids across repositories Caleb White
2024-11-29 3:14 ` Junio C Hamano
2024-11-29 3:31 ` Caleb White
2024-12-01 4:38 ` Junio C Hamano [this message]
2024-11-29 11:05 ` shejialuo
2024-11-29 15:58 ` Caleb White
2024-11-29 17:32 ` shejialuo
2024-11-29 20:39 ` Caleb White
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=xmqq34j8m30t.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=cdwhite3@pm.me \
--cc=git@vger.kernel.org \
/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.