Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, Elijah Newren <newren@gmail.com>,
	Junio C Hamano <gitster@pobox.com>, Tian Yuchen <cat@malon.dev>
Subject: Re: [PATCH v2 02/18] setup: stop using `the_repository` in `is_inside_worktree()`
Date: Tue, 19 May 2026 11:47:44 +0200	[thread overview]
Message-ID: <agwxwNIfZuwj9qod@pks.im> (raw)
In-Reply-To: <CAOLa=ZT2Qo+oJ1rx2iM3QRcXMGaucFRJdxBAgxBdz3ZtgSb=Qg@mail.gmail.com>

On Tue, May 19, 2026 at 01:23:21AM -0700, Karthik Nayak wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > The function `is_inside_worktree()` verifies whether or not the current
> 
> Nit: Here and the subject s/is_inside_worktree/is_inside_work_tree/
> 
> Honestly, I would prefer `worktree` as that's what we've used through
> out the code base, but that is probably out of scope here.

Oh, good eyes.

> > Note that there is one small gotcha: we sometimes may end up with
> > relative directory paths, and if so `is_inside_dir()` might fail. This
> > wasn't an issue before because of how we proactively set the cached
> > value during repository discovery. Now that we stop doing that it
> > becomes a problem though, but it is worked around by resolving the
> > repository directory via `realpath()`.
> >
> 
> Curious if you discovered this via a test. But running the tests
> without `realpath()` didn't trigger any failures. Is this something we
> can add a test for?

No, I wasn't able to come up with a test for this. I think overall the
paragraph could use some tweaking as it's warning about something that
cannot happen right now.

Originally, I had the order of `is_inside_work_tree()` and
`is_inside_git_dir()` reversed, and I had most of the commit message in
`is_inside_git_dir()`. So this explanation here was originally part of
the gitdir commit, and here it is correct: when setting the repo's
gitdir we don't resolve it to its real path. And not using the real path
does make tests fail in this case.

But this is different for the work tree: the only caller that sets
the repository's worktree is `repo_set_worktree()`, and that function
does use `real_pathdup()` to resolve the path. So we know that the
worktree is always the absolute resolved path, and consequently it's
unnecessary to resolve the variable again.

So there's two ways to handle that:

  - We could be defensive about it and continue to allow a relative or
    non-resolved worktree path here and manually resolve.

  - We could rely on the fact that currently the worktree path is always
    resolved anyway.

I think a world where we only ever use absolute paths is preferable, but
I honestly don't trust our repository setup infrastructure enough to say
that this assumption will never break. Furthermore, it would create some
asymmetry between `is_inside_git_dir()` and `is_inside_work_tree()` that
is overall a bit puzzling.

I guess the proper fix for this would be to also change the repository's
gitdir to be an absolute path. But that would result in a bunch of
user-visible changes, both in error messages and in commands like `git
rev-parse --git-common-dir`.

Meanwhile I'm more leaning into the direction of keeping the code
as-is, but correct the commit message.

Thanks!

Patrick

  reply	other threads:[~2026-05-19  9:47 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  8:22 [PATCH 00/18] setup: drop uses of `the_repository` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 01/18] setup: replace use of `the_repository` in static functions Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 02/18] setup: stop using `the_repository` in `is_inside_worktree()` Patrick Steinhardt
2026-05-17 16:18   ` Tian Yuchen
2026-05-17 23:41     ` Junio C Hamano
2026-05-18  7:46       ` Patrick Steinhardt
2026-05-19  1:22         ` Junio C Hamano
2026-05-19  9:50           ` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 03/18] setup: stop using `the_repository` in `is_inside_git_dir()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 04/18] setup: stop using `the_repository` in `prefix_path()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 05/18] setup: stop using `the_repository` in `path_inside_repo()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 06/18] setup: stop using `the_repository` in `verify_filename()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 07/18] setup: stop using `the_repository` in `verify_non_filename()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 08/18] setup: stop using `the_repository` in `enter_repo()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 09/18] setup: stop using `the_repository` in `setup_work_tree()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 10/18] setup: stop using `the_repository` in `set_git_work_tree()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 11/18] setup: stop using `the_repository` in `setup_git_env()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 12/18] setup: stop using `the_repository` in `setup_git_directory_gently()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 13/18] setup: stop using `the_repository` in `setup_git_directory()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 14/18] setup: stop using `the_repository` in `upgrade_repository_format()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 15/18] setup: stop using `the_repository` in `check_repository_format()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 16/18] setup: stop using `the_repository` in `initialize_repository_version()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 17/18] setup: stop using `the_repository` in `create_reference_database()` Patrick Steinhardt
2026-04-20  8:22 ` [PATCH 18/18] setup: stop using `the_repository` in `init_db()` Patrick Steinhardt
2026-04-20 15:50 ` [PATCH 00/18] setup: drop uses of `the_repository` Elijah Newren
2026-04-21  9:41   ` Patrick Steinhardt
2026-04-20 17:11 ` Junio C Hamano
2026-04-21  9:41   ` Patrick Steinhardt
2026-05-18  9:30 ` [PATCH v2 " Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 01/18] setup: replace use of `the_repository` in static functions Patrick Steinhardt
2026-05-19  8:03     ` Karthik Nayak
2026-05-18  9:30   ` [PATCH v2 02/18] setup: stop using `the_repository` in `is_inside_worktree()` Patrick Steinhardt
2026-05-19  8:23     ` Karthik Nayak
2026-05-19  9:47       ` Patrick Steinhardt [this message]
2026-05-18  9:30   ` [PATCH v2 03/18] setup: stop using `the_repository` in `is_inside_git_dir()` Patrick Steinhardt
2026-05-19  8:25     ` Karthik Nayak
2026-05-18  9:30   ` [PATCH v2 04/18] setup: stop using `the_repository` in `prefix_path()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 05/18] setup: stop using `the_repository` in `path_inside_repo()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 06/18] setup: stop using `the_repository` in `verify_filename()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 07/18] setup: stop using `the_repository` in `verify_non_filename()` Patrick Steinhardt
2026-05-18  9:30   ` [PATCH v2 08/18] setup: stop using `the_repository` in `enter_repo()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 09/18] setup: stop using `the_repository` in `setup_work_tree()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 10/18] setup: stop using `the_repository` in `set_git_work_tree()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 11/18] setup: stop using `the_repository` in `setup_git_env()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 12/18] setup: stop using `the_repository` in `setup_git_directory_gently()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 13/18] setup: stop using `the_repository` in `setup_git_directory()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 14/18] setup: stop using `the_repository` in `upgrade_repository_format()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 15/18] setup: stop using `the_repository` in `check_repository_format()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 16/18] setup: stop using `the_repository` in `initialize_repository_version()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 17/18] setup: stop using `the_repository` in `create_reference_database()` Patrick Steinhardt
2026-05-18  9:31   ` [PATCH v2 18/18] setup: stop using `the_repository` in `init_db()` Patrick Steinhardt
2026-05-19  9:26   ` [PATCH v2 00/18] setup: drop uses of `the_repository` Karthik Nayak
2026-05-19  9:51     ` Patrick Steinhardt
2026-05-19  9:52 ` [PATCH v3 " Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 01/18] setup: replace use of `the_repository` in static functions Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 02/18] setup: stop using `the_repository` in `is_inside_git_dir()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 03/18] setup: stop using `the_repository` in `is_inside_work_tree()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 04/18] setup: stop using `the_repository` in `prefix_path()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 05/18] setup: stop using `the_repository` in `path_inside_repo()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 06/18] setup: stop using `the_repository` in `verify_filename()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 07/18] setup: stop using `the_repository` in `verify_non_filename()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 08/18] setup: stop using `the_repository` in `enter_repo()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 09/18] setup: stop using `the_repository` in `setup_work_tree()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 10/18] setup: stop using `the_repository` in `set_git_work_tree()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 11/18] setup: stop using `the_repository` in `setup_git_env()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 12/18] setup: stop using `the_repository` in `setup_git_directory_gently()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 13/18] setup: stop using `the_repository` in `setup_git_directory()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 14/18] setup: stop using `the_repository` in `upgrade_repository_format()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 15/18] setup: stop using `the_repository` in `check_repository_format()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 16/18] setup: stop using `the_repository` in `initialize_repository_version()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 17/18] setup: stop using `the_repository` in `create_reference_database()` Patrick Steinhardt
2026-05-19  9:52   ` [PATCH v3 18/18] setup: stop using `the_repository` in `init_db()` Patrick Steinhardt

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=agwxwNIfZuwj9qod@pks.im \
    --to=ps@pks.im \
    --cc=cat@malon.dev \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=newren@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