]> git.ipfire.org Git - thirdparty/git.git/commit
setup: stop using `the_repository` in `is_inside_git_dir()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 19 May 2026 09:52:06 +0000 (11:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2026 10:36:23 +0000 (19:36 +0900)
commitce70cbc294f2f1f9a853307d35a78baa16207e58
treeee6f72b3f125a242ee43bd618d03263a96773603
parentbb50ec6b26a37789208c18d0d3f7cbf047090145
setup: stop using `the_repository` in `is_inside_git_dir()`

The function `is_inside_git_dir()` verifies whether or not the current
working directory is located inside the gitdir of `the_repository`. This
is done by taking the gitdir path and verifying that it's a prefix of
the current working directory.

This information is cached so that we don't have to re-do this change
multiple times. Furthermore, we proactively set the value in multiple
locations so that we don't even have to perform the check when we have
discovered the repository.

While we could simply move the caching variable into the repository, the
current layout doesn't really feel sensible in the first place:

  - It can easily lead to false positives or negatives if at any point
    in time we may switch the current working directory.

  - We don't call the function in a hot loop, and neither is it overly
    expensive to compute.

Drop the caching infrastructure and instead compute the property ad-hoc
via an injected repository.

Note that there is one small gotcha: we often end up with relative
gitdir 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, which we work around by resolving the gitdir via `realpath()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rev-parse.c
setup.c
setup.h