From: Junio C Hamano <gitster@pobox.com>
To: "Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Eric Sunshine <sunshine@sunshineco.com>,
Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Subject: Re: [PATCH v2 5/5] worktree repair: avoid breaking unrelated .git file and gitdir
Date: Thu, 15 Oct 2026 11:03:38 -0700 [thread overview]
Message-ID: <xmqq8q3yon7p.fsf@gitster.g> (raw)
In-Reply-To: <015602168c8532c07b94c9f50925bf5d5a2ef7c8.1792012836.git.gitgitgadget@gmail.com> (Yoichi NAKAYAMA via GitGitGadget's message of "Wed, 14 Oct 2026 21:20:36 +0000")
"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.
next prev parent reply other threads:[~2026-10-15 18:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-13 3:20 [PATCH 0/2] worktree repair: avoid breaking unrelated .git file and gitdir Yoichi NAKAYAMA via GitGitGadget
2026-09-13 3:20 ` [PATCH 1/2] worktree repair: refactor and reduce .git file reads Yoichi NAKAYAMA via GitGitGadget
2026-10-08 20:55 ` Junio C Hamano
2026-10-11 16:16 ` Yoichi NAKAYAMA
2026-10-12 19:57 ` Yoichi NAKAYAMA
2026-09-13 3:20 ` [PATCH 2/2] worktree repair: avoid breaking unrelated .git file and gitdir Yoichi NAKAYAMA via GitGitGadget
2026-10-08 3:50 ` [PATCH 0/2] " Yoichi NAKAYAMA
2026-10-14 21:20 ` [PATCH v2 0/5] " Yoichi NAKAYAMA via GitGitGadget
2026-10-14 21:20 ` [PATCH v2 1/5] worktree repair: align .git file handling with repair_gitfile() Yoichi NAKAYAMA via GitGitGadget
2026-10-14 21:20 ` [PATCH v2 2/5] worktree repair: centralize inferred backlink selection Yoichi NAKAYAMA via GitGitGadget
2026-10-14 21:20 ` [PATCH v2 3/5] worktree repair: use read_gitfile_raw() in infer_backlink() Yoichi NAKAYAMA via GitGitGadget
2026-10-14 21:20 ` [PATCH v2 4/5] worktree repair: reduce .git file reads Yoichi NAKAYAMA via GitGitGadget
2026-10-14 21:20 ` [PATCH v2 5/5] worktree repair: avoid breaking unrelated .git file and gitdir Yoichi NAKAYAMA via GitGitGadget
2026-10-15 18:03 ` Junio C Hamano [this message]
2026-10-14 22:46 ` [PATCH v2 0/5] " Junio C Hamano
2026-10-15 13:41 ` Yoichi NAKAYAMA
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=xmqq8q3yon7p.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=sunshine@sunshineco.com \
--cc=yoichi.nakayama@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