]> git.ipfire.org Git - thirdparty/git.git/commit
safe.directory: preliminary clean-up
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Jul 2024 18:43:49 +0000 (11:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Jul 2024 18:47:58 +0000 (11:47 -0700)
commit1048aa8b7ad44d6c759e894f6ca763614068514d
tree8c80c299212496377ba06d30bd5e2f4701b843c9
parentd19b6cd2dd72dc811f19df4b32c7ed223256c3ee
safe.directory: preliminary clean-up

The paths given in the safe.directory configuration variable are
allowed to contain "~user" (which interpolates to user's home
directory) and "%(prefix)" (which interpolates to the installation
location in RUNTIME_PREFIX-enabled builds, and a call to the
git_config_pathname() function is tasked to obtain a copy of the
path with these constructs interpolated.

The function, when it succeeds, always yields an allocated string in
the location given as the out-parameter; even when there is nothing
to interpolate in the original, a literal copy is made.  The code
path that contains this caller somehow made two contradicting and
incorrect assumptions of the behaviour when there is no need for
interpolation, and was written with extra defensiveness against
two phantom risks that do not exist.

One wrong assumption was that the function might yield NULL when
there is no interpolation.  This led to the use of an extra "check"
variable, conditionally holding either the interpolated or the
original string.  The assumption was with us since 8959555c
(setup_git_directory(): add an owner check for the top-level
directory, 2022-03-02) originally introduced the safe.directory
feature.

Another wrong assumption was that the function might yield the same
pointer as the input when there is no interpolation.  This led to a
conditional free'ing of the interpolated copy, that the conditional
never skipped, as we always received an allocated string.

Simplify the code by removing the extra defensiveness.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c