Article View: linux.kernel.git
Article #712Re: [PATCH v2 5/5] worktree repair: avoid breaking unrelated .git file and gitdir
From: Yoichi NAKAYAMA
Date: Sat, 17 Oct 2026 02:40
Date: Sat, 17 Oct 2026 02:40
56 lines
11454 bytes
11454 bytes
On Fri, Oct 16, 2026 at 3:03 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > diff --git a/worktree.c b/worktree.c
> > index 879941a977..86094307b1 100644
> > --- a/worktree.c
> > +++ b/worktree.c
> > @@ -640,7 +640,11 @@ int other_head_refs(struct repository *repo,
> > static const char *get_worktree_id(const char *dotgit_contents)
> > {
> > const char *slash = find_last_dir_sep(dotgit_contents);
> > - if (!slash)
> > + const char *prefix = "/worktrees";
> > + int prefixlen = strlen(prefix);
> > + if (!slash ||
> > + slash - dotgit_contents < prefixlen ||
> > + strncmp(slash - prefixlen, prefix, prefixlen))
> > return "";
> > return slash + 1;
>
> Just being curious, but slash is found by scanning dotgit_contents
> for either '/' or '\'. We make sure what comes before the slash
> is "/worktree".
>
> Could there be situations where this code needs to accept
>
> "...\worktrees\my-worktree"
>
> where slash points at the backslash before "my-worktree"? Because
> somebody wrote the pathname with backslash before the worktree name,
> it would be natural to expect another backslash before the "worktrees"
> constant, no? For that matter, would this code need to also accept
>
> ".../worktrees//my-worktree"
>
> where three are extra/duplicated slashes (or backslashes)? The
> normal code paths to create these directories and records the path
> to these directories should hopefully be using the canonical '/'
> without unnecessary duplicate slashes, but (1) existing use of
> find_last_dir_sep() might be a sign that we may have to deal with
> backslashes, and (2) since this is about reparing a broken set-up,
> it does not seem too far-fetched to attempt dealing with the above
> two sample input, hence this question.
While Git doesn't create a .git file with backslash separators,
it can find the repository from such .git file on Windows.
So I think 'worktree repair' should handle it.
I will also add handling for duplicated separators.
Thanks,
--
Yoichi NAKAYAMA
Technical Details
Message-ID:
<CAF5D8-tTmruFLpCY4WpCkMU+3ng9pHp22MrTcUrKbXfWmhzoow@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72282-linux-kernel-git=dewy.ruReferences:
<pull.2225.git.1789269613.gitgitgadget@gmail.com> <pull.2225.v2.git.1792012836.gitgitgadget@gmail.com> <015602168c8532c07b94c9f50925bf5d5a2ef7c8.1792012836.git.gitgitgadget@gmail.com> <xmqq8q3yon7p.fsf@gitster.g>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72282-linux-kernel-git=dewy.ru
From: yoichi.nakayama@gmail.com (Yoichi NAKAYAMA)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2 5/5] worktree repair: avoid breaking unrelated .git
file and gitdir
Date: Sat, 17 Oct 2026 11:40:03 +0900
Organization: Usenet Network
Message-ID: <CAF5D8-tTmruFLpCY4WpCkMU+3ng9pHp22MrTcUrKbXfWmhzoow@mail.gmail.com>
References: <pull.2225.git.1789269613.gitgitgadget@gmail.com>
<pull.2225.v2.git.1792012836.gitgitgadget@gmail.com> <015602168c8532c07b94c9f50925bf5d5a2ef7c8.1792012836.git.gitgitgadget@gmail.com>
<xmqq8q3yon7p.fsf@gitster.g>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="2947490"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:udCkONY45l51IOyKer74pRKHA24= sha256:zK3M76sdVADPmaZPPef0z3W+FIesKkz73KdSKMX6Dzw=
sha1:wktXxkT8k52GOh6/g4LMgPCbOO0= sha256:5tMpcY7JH6dlOcujG8Q7SXJLBCkgEI46BHCQ2os6vOQ=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id CAE31110671; Sat, 17 Oct 2026 05:40:40 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id XXL9OQEpYrau;
Sat, 17 Oct 2026 05:40:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72282-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id BCCA9110668; Sat, 17 Oct 2026 05:40:28 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 8FB202C6C3; Sat, 17 Oct 2026 02:40:18 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 710753911C7;
Sat, 17 Oct 2026 02:40:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VnliDs/w"
X-Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AB9433F36D
for <git@vger.kernel.org>; Sat, 17 Oct 2026 02:40:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.222.174
X-ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792204817; cv=pass; b=ucPFC2kN5/AeTYTPTxM4FlRXceIn3awGYxrLITubAIY+3JBR1x3Q03GPU2yhBVy1MVFo0PdV4Sign1dMcqvt8oKiuCZ7jLznbBGX0mG/CAZVK0y5g9KjEeDmDBhGK/uzwxAyqBvOewuB24QVCiVXA38xKJgS0rLjNvqjr81LEqA=
X-ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792204817; c=relaxed/simple;
bh=Gh+7GoJAQTui695FyG/RD4USGQS9k42af5/F02oNzbM=;
h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
To:Cc:Content-Type; b=Z3z4z9xa7tIqjtNOp67qsEA2dSxKJMUc73ZveFZ4EzcQwXtWsiDAZJiPYpJhjNJfZiyudEj9artnPTF1THNkoZpnqKjLAewdP0W9ccEw+DzS/U0SFN1N74cUt/V+WCh9dZVOkCdsNJ5xASjbbuQOwUzPpgVlh8QoEoO5Dpt6FLg=
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VnliDs/w; arc=pass smtp.client-ip=209.85.222.174
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-93f2ed2541aso6498785a.0
for <git@vger.kernel.org>; Fri, 16 Oct 2026 19:40:15 -0700 (PDT)
X-ARC-Seal: i=1; a=rsa-sha256; t=1792204815; cv=none;
d=google.com; s=arc-20260327;
b=UzfaRWarsdVH/GNeQrzgVjtFZTOkA0BEzPbzZXorN1dDAlOJl5wTqdzTHQva+kHEAo
3eJZIEJyTdYIEdtnGfwybgzGYUSNsKZQiPDiaHDyp7cC7UvW87zduK+4Cw1YEmTVMWwz
nnc1RtnoM7nUEbuh6C4GqY/KEP+kl7EfUTMolrBcexR08uir5W77bzMNdL+cUhlTvfyb
6NWwe3k/EjDBFzwJR5LEjdWxSBLuAWG0xnJp+DsWCZYO/0yLV31pEfhzrh+6Wkclgw5+
ME6DnkXL1pHEz9wYfiBfIKLVM3B+fvH8N7XDpDcuZ97XpwrUx05rV6JpnGwwSYp1sKzx
Cr9Q==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:dkim-signature;
bh=PXiz2+8JyPJjEVRKTQBCZh9O6fJH13cZ7uijstHx6yc=;
fh=rhEurnMte3dV9eajID4p+GrSHRwwpir9bkV2O3A+wK4=;
b=C72LXoJUl0AO5CdcM/VSNg39+0Wkwe6qe+GxzMNxmREaYmELACx0hdLLaWyBfOuNEw
mSufN1vK5SP5XqWSE7fscS6H53fqUK4ylSwmWieQqSiLQrKfWdVbuTwkHKF7onJCj253
kfCaX8YtsYIy8LDnTa5E6OU0QjbCYpsDGwBPwCokEVfPUx9KSJlcfRdhZRtxq5L6sZn5
mqLzpCbHQuhfN9fL9zBoALlyiw3B95nYRTkgEzP2BD7SX1bvTjTSyF1R8/r1x+TMt6AY
v2kdwzD9yCsr8YwB4zVFzXhpWlzrn+OxsFxBV2JRpFWqHOQM54U825lWRjIPk98piICx
WC8Q==;
darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792204815; x=1792809615; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=PXiz2+8JyPJjEVRKTQBCZh9O6fJH13cZ7uijstHx6yc=;
b=VnliDs/wFS2m4GsYO+9rRy1dlhu0WdTAN91xVVWWywY3OXIOReMPMD9RTxGmFhxkmA
1SGpRDilFdE7QXuyjPyEERqJQsI8At0hHlJCvnU0v4ASD8W1qkQz9UFLI4EPVYAKpmVa
qKjghklfWIKG+Q7xJvY7iwqcIwKFeJ4KfpTLiWMNtc5ZM1J0XbkxqxyJgalPcuGgLe4W
Aby2y3+BgzN4WVXJzJezu/72kOO+NMrKaKKriwqtg7On/5iI4AuQ3xPJ/OtK2exU4Qrz
Wuf4QOfewtpEzON02iA/Q2Nik0ozeXAw8S3qlFTDHIOw2St0zxnK+vPfKRj7LoCqCoo2
bKIA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792204815; x=1792809615;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=PXiz2+8JyPJjEVRKTQBCZh9O6fJH13cZ7uijstHx6yc=;
b=X69fF2r6p70rqUOAnIpxxC7iwcLO7PbEAV12jYZuIKHtC8c1Kcs6+Rj3u1di17e3rh
ATOAk7OmW2tMPkYamuSFHUBk2Okhd24M/IORsE9935vJIa++V5VP8T6zvlUbdblygx+D
AfwnYgrGrFPMlsTedQJ2Nk+YbHrswVkmper/BqUQEmc1qiZMDmUao+xOFdA/Lofm5sgB
mNHsjZgjhtzLAEjVU4/82X77gMagQklf7Zow75tPpn0/MprSaclM+An1vGWpDjxnvvOj
j/eU6XxkClOpmH5AipnX4FEAsAw5MShIeQrw2QGUw5r8FW3MqOm2gYf3gbGj0yDiR/ha
S+5w==
X-Forwarded-Encrypted: i=1; AKwUvBymOPdVvq7gqPQIaoxfOsvz0qBEjFSml7apBwV24+KEuQ0D7KEwFerCCZIv6eJ7G4btWFY=@vger.kernel.org
X-Gm-Message-State: AFq9FYKvyBNXpdbXbN8BUmvG04tmr5OqCtvbeMuBbtetCMB0+t+3DTVQ
KpbMTrBpxoQH1xpJFkx6qKhtJQ/OWpe36rEH4xGf/nXxWtMuCWBOV8qaE7nbmmeR86LBw9h2TW0
Cs8Lk1Fe5qSeBfF6DZvU2HEZM1tZpyQCEwwUW
X-Gm-Gg: AYBFou0FpwfY7LPjHMl4vNZzPn8/UxMRG/YUp2I3/biQQESxb/dbOhTkvPy5qJhc+1F
BiSkQ50/L/x+lAyJfjot2GE7rOIhxtCMJ2OuBvoEntHjUi2cl9o/ABXIYBkjY0mHwGkF5Swcshc
0Gqg2EYE295UkCHdRHNd6f/9RlyQyrb/qT7ewf79dB9UM3D1CCHHUltwGMzSEgiCXy5N7RCKN4m
MHxFlGOKGC4sVc2f9uW/roMWDZDEuVze82//JKEal/SJ81gH+kduaSgYGp8XdDEXoDSpiXssEYH
GZ5Cgyq1PMzHo/3ix92SAPh9Ea0XcvRrBzAvOauAcSLZDLX8lZYwK2ZIHZCio0HH4/8pUay1pKD
6Pg1giJ7XZeRd3y+zM9QMfi5A2JV0nRpz3LdMIPf97dOx
X-Received: by 2002:a05:620a:6507:b0:93b:d88b:ee01 with SMTP id
af79cd13be357-93f17f8aabcmr814595185a.34.1792204814974; Fri, 16 Oct 2026
19:40:14 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-In-Reply-To: <xmqq8q3yon7p.fsf@gitster.g>
X-Gm-Features: AclHuK-X7Qj-PfTPeTGBG5QCzoxPGWWuQs9K-Ix0WReI8VB4Vfy4D1Skvl56iYg
X-Cc: Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com>, git@vger.kernel.org,
Eric Sunshine <sunshine@sunshineco.com>