Article View: linux.kernel.git
Article #613Re: [PATCH v2 5/5] worktree repair: avoid breaking unrelated .git file and gitdir
From: Junio C Hamano
Date: Thu, 15 Oct 2026 18:03
Date: Thu, 15 Oct 2026 18:03
45 lines
11447 bytes
11447 bytes
"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.
Thanks.
Technical Details
Message-ID:
<xmqq8q3yon7p.fsf@gitster.g>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72166-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>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-72166-linux-kernel-git=dewy.ru
From: gitster@pobox.com (Junio C Hamano)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2 5/5] worktree repair: avoid breaking unrelated .git
file and gitdir
Date: Thu, 15 Oct 2026 11:03:38 -0700
Organization: Usenet Network
Message-ID: <xmqq8q3yon7p.fsf@gitster.g>
References: <pull.2225.git.1789269613.gitgitgadget@gmail.com>
<pull.2225.v2.git.1792012836.gitgitgadget@gmail.com>
<015602168c8532c07b94c9f50925bf5d5a2ef7c8.1792012836.git.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: usenet.network;
logging-data="2586970"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:HqhWrarh9y3MvrIN5RGjB64GtN4= sha256:N7zEPYQvBqa6EvMP1HlW3TiYXz4H7TNoBys/G3/+vJo=
sha1:AsGC8UdWVQpA7/x07GSyz5mwK4Q= sha256:F+9AIJtEUjj62YmwtA9KXIjkPZ9QXHRbcCrm3FcTghw=
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 2C6FE110381; Thu, 15 Oct 2026 21:04:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.75
X-Spam-Status: No, score=-0.75 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, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, 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=pobox.com header.b=HGhnDhYq; dkim=pass (2048-bit key)
header.d=messagingengine.com header.b=Cgj1dLgt
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 Oa4Pkwvdg4n5;
Thu, 15 Oct 2026 21:04:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-72166-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=pobox.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id 30D70110029; Thu, 15 Oct 2026 21:03:59 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sin.lore.kernel.org (Postfix) with ESMTP id 777DF23EF0; Thu, 15 Oct 2026 18:03:51 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 331B536D9EE;
Thu, 15 Oct 2026 18:03:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="HGhnDhYq";
dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Cgj1dLgt"
X-Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49198392811
for <git@vger.kernel.org>; Thu, 15 Oct 2026 18:03:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.147
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792087426; cv=none; b=oU4B0jAyjyhfpedeiA68Z4uxsWZvgBMN3ZD0WR7RIEazz+/vtJ6NO+HxdEfNXewvqTaMiHTVnIsQe1AxuBkkLZWxIn5GCL1oKQBI/QnMk6maBNStpiDCQYcrGcoTGpfu7CDn8C3HSssGNnKVjmyOL6Bbj8Kx3NNrr7FnJ+SJTI8=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792087426; c=relaxed/simple;
bh=pF64kygpsSmr5wsEZWF3g7UNwqMVwqETcKbPKNn32DQ=;
h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
MIME-Version:Content-Type; b=E91EQan1hmfwapOY7f244yp/dYQ5F3ljPF4L3I1uX/364sIfHSBONjd27r4cKBfEvYiblUPzoSyMJDSBo8XvEl/yrQN+uXPmuS8hMHCVL77UDDyNcoE9zCDzZkgQeSCa2p8LbcUodY4OhyfTuLhbiKT6GWgsOD9x2pzAF++hXiI=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=HGhnDhYq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Cgj1dLgt; arc=none smtp.client-ip=202.12.124.147
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com
X-Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41])
by mailfout.stl.internal (Postfix) with ESMTP id 7E1201D00127
for <git@vger.kernel.org>; Thu, 15 Oct 2026 14:03:40 -0400 (EDT)
X-Received: from phl-frontend-01 ([10.202.2.160])
by phl-compute-01.internal (MEProxy); Thu, 15 Oct 2026 14:03:40 -0400
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc
:cc:content-type:content-type:date:date:from:from:in-reply-to
:in-reply-to:message-id:mime-version:references:reply-to:subject
:subject:to:to; s=fm1; t=1792087420; x=1792173820; bh=RWLCgug8lo
K1sYO0w7Yr9ZHbTLKc1D9eCmxPsA4D3/c=; b=HGhnDhYqFPLALa1l6G3hiz4FRs
6uG79ZG/nzhaUcr6utaRrtsgCvUbwtOU0xMMMLOO0hgiiatnOr6wPcgzicQ8Y+se
RsI9yzKvEkGP1l1qyiAwS7nQE4JL+ILJOUTU6li7ZEsuf3Yf4wBRk3C3FNpkwmEj
uPvJluABaqXRJe890jx0wsyd7MKTQ2Nj2aqW3h6bJ1M80+aiHhdFuNdDPyKEfP2j
baT26A9DrfYw7VVUVddyBmRlfrCI33oJz3cLHdTfkbrJ2grFwP5UyG4IVx3Mzy9D
xpyHMY0YMZlC1nnp2E3wtamnSyDPMCiXFOV4m+8mFTBldF6KWXqOvQ4o0bqg==
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:cc:content-type:content-type:date:date
:feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
:message-id:mime-version:references:reply-to:subject:subject:to
:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=
1792087420; x=1792173820; bh=RWLCgug8loK1sYO0w7Yr9ZHbTLKc1D9eCmx
PsA4D3/c=; b=Cgj1dLgtM4ofgCu1IHntETOqfq5B7KEBUZn2saIfoT2DgQhoCLj
U3L4O96yQh5vNFSlsK38GTZaMkD1UN1kbHEBcsazaBjCxOfXqaeH1jEFWXQMsbG/
hCiNWfQl6Vfwz+m6sI1JhwalScFlGctPv8Bba5sFY/RLsvJomtE2KKZGYyjyTc5w
07BQhaNbq0tCRlVRUumn0nKsx+d6wyWaA7pZPXa/PhP62XjFmvtvFIpw3LITijXZ
oTSfiDkxnDffmvTOsvxM55pob4zHkYYt8yNXmb90IyTjHLx6qZM2rflkPExmoQw5
MQBAyvIJaZscPJBS3B6CUy42xqc3ClsbXNg==
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06;
repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox;
action=sign d=pobox.com a=rsa-sha256;
X-DKIM2-Signature: i=1; m=1; t=1792087420; d=pobox.com;
mf=PGdpdHN0ZXJAcG9ib3guY29tPg==;
rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+;
s=fm1:rsa-sha256:N7nXrLKjOIre9icCR0Z5zPcB8J9+bDTq5qUAvvHTVBrZeoo
juRempaokC+Pmja59dJDrIiHpqJUdySEwroLFB4uAr65jGtFoIz1bObeby+t7l+Q
jWgKNOtrEbAAd4Xj/DflBlFoJ6gI1VsX0gsxH3K/SoEM+wkORABk49HfQfWc3THe
M/CdfmyrrDpgB5HK9p98f1OIyS5hcA48DIt1HeOTQjlBbku6AwMt1ckuJ05glGZt
lNL5WR21DSxqlQlXBEsDpdEyAn2fDQfgOpfpJszYeMmNffGWB8QzuFiOnZiMFT4a
NFjmktR4stgrsYD8Ynb72JYwAIhXQQKOc8bPqpQ==;
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06;
repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox;
action=mi-m=1; hc=12;
hn=cc,content-type,date,feedback-id,from,in-reply-to,message-id,
mime-version,references,subject,to,user-agent;
X-Message-Instance: m=1; h=sha256:T6+Iwq/qo+0En/kWWhPjz2LqsA136Tz/a/z3hFtZHNQ=:pF64kygpsSmr5wsEZWF3g7UNwqMVwqETcKbPKNn32DQ=;
X-ME-Sender: <xms:fBXRamFbWTYA6jAelhOSI6wZLMVs61U-_Q6Qa1pB0vWk8RUmP4lt2A>
<xme:fBXRauP0veJytEWgsR7v7ym8-3f4vVoJtEAQ4e5-fzjFArxc_N0B6-DqXJPm8T1Sp
W4DewYjDuLSmhz0zKQrL7SEmF2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d_i-Rlm-D25IeutMdAYcwA>
<xmx:fBXRajdm0pL4_lVMXYtU8VeLcvtAos5kmUtxszykd8_QPYYCjFnzFCUy>
X-Feedback-ID: if26b431b:Fastmail
X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu,
15 Oct 2026 14:03:39 -0400 (EDT)
X-Cc: git@vger.kernel.org, Eric Sunshine <sunshine@sunshineco.com>, Yoichi
NAKAYAMA <yoichi.nakayama@gmail.com>
X-In-Reply-To: <015602168c8532c07b94c9f50925bf5d5a2ef7c8.1792012836.git.gitgitgadget@gmail.com>
(Yoichi NAKAYAMA via GitGitGadget's message of "Wed, 14 Oct 2026
21:20:36 +0000")
X-User-Agent: Gnus/5.13 (Gnus v5.13)
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>