]> git.ipfire.org Git - thirdparty/git.git/commit - setup.c
setup_git_directory_1(): avoid changing global state
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 13 Mar 2017 20:10:42 +0000 (21:10 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Mar 2017 21:24:16 +0000 (14:24 -0700)
commitce9b8aab5d9a40a84b4868fa890654900ab2d4cc
tree32efa4a4d030ab0d31a5d69aee9436b3a1874320
parentdf380d58ece2a745e4283ef4de8dfeea560546bb
setup_git_directory_1(): avoid changing global state

For historical reasons, Git searches for the .git/ directory (or the
.git file) by changing the working directory successively to the parent
directory of the current directory, until either anything was found or
until a ceiling or a mount point is hit.

Further global state may be changed in case a .git/ directory was found.

We do have a use case, though, where we would like to find the .git/
directory without having any global state touched, though: when we read
the early config e.g. for the pager or for alias expansion.

Let's just move all of code that changes any global state out of the
function `setup_git_directory_gently_1()` into
`setup_git_directory_gently()`.

In subsequent patches, we will use the _1() function in a new
`discover_git_directory()` function that we will then use for the early
config code.

Note: the new loop is a *little* tricky, as we have to handle the root
directory specially: we cannot simply strip away the last component
including the slash, as the root directory only has that slash. To remedy
that, we introduce the `min_offset` variable that holds the minimal length
of an absolute path, and using that to special-case the root directory,
including an early exit before trying to find the parent of the root
directory.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c