]> git.ipfire.org Git - thirdparty/git.git/commit
gc: replace config subprocesses with API calls
authorDerrick Stolee <derrickstolee@github.com>
Tue, 27 Sep 2022 13:57:00 +0000 (13:57 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Sep 2022 16:32:26 +0000 (09:32 -0700)
commit50a044f1e407ef217cb5d057af08e9e87daddc78
treeb7c8e1d82efe61206ef3c4958eabe92f85ae0e25
parentd871b6c6c634689134a92d068bfb066d77d8429d
gc: replace config subprocesses with API calls

The 'git maintenance [un]register' commands set or unset the multi-
valued maintenance.repo config key with the absolute path of the current
repository. These are set in the global config file.

Instead of calling a subcommand and creating a new process, create the
proper API calls to git_config_set_multivar_in_file_gently(). It
requires loading the filename for the global config file (and erroring
out if now $HOME value is set). We also need to be careful about using
CONFIG_REGEX_NONE when adding the value and using
CONFIG_FLAGS_FIXED_VALUE when removing the value. In both cases, we
check that the value already exists (this check already existed for
'unregister').

Also, remove the transparent translation of the error code from the
config API to the exit code of 'git maintenance'. Instead, use die() to
recover from failures at that level. In the case of 'unregister
--force', allow the CONFIG_NOTHING_SET error code to be a success. This
allows a possible race where another process removes the config value.
The end result is that the config value is not set anymore, so we can
treat this as a success.

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c