Re: [PATCH v2 3/4] config: factor out global config file retrieval
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 16, 2024, 21:39 UTC
- Message-ID
- <xmqqcyu1yn36.fsf@gitster.g>
- In-Reply-To
- <32e5ec7d866ff8fd26554b325812c6e19cb65126.1705267839.git.code@khaugsbakk.name>
Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
Show 24 quoted lines
> if (use_global_config) {
> - char *user_config, *xdg_config;
> ...
> - else if (use_system_config) {
> + } else if (use_system_config) {
> given_config_source.file = git_system_config();
> given_config_source.scope = CONFIG_SCOPE_SYSTEM;
> } else if (use_local_config) {
> diff --git a/config.c b/config.c
> index ebc6a57e1c3..3cfeb3d8bd9 100644
> --- a/config.c
> +++ b/config.c
> @@ -1987,6 +1987,26 @@ char *git_system_config(void)
> return system_config;
> }
>
> +char *git_global_config(void)
> +{
> +...
> +}
> +
> void git_global_config_paths(char **user_out, char **xdg_out)
> {
> char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL"));The conversion above
Show 11 quoted lines
> diff --git a/config.h b/config.h > index e5e523553cc..625e932b993 100644 > --- a/config.h > +++ b/config.h > @@ -382,6 +382,10 @@ int config_error_nonbool(const char *); > #endif > > char *git_system_config(void); > +/** > + * Returns `NULL` if is uncertain whether or not `HOME/.gitconfig` exists. > + */
Sorry, but I am not sure what this comment wants to say.
When $HOME is not set, we do get NULL out of this function. But interpolate_path() that makes git_global_config_paths() to return NULL in user_config does not do any existence check with stat() or access(), so even when we return a string that is "~/.gitconfig" expanded to '/home/user/.gitconfig", we are not certain if the file exists. So,... it is unclear what "uncertain"ty we are talking about in this case.
> +char *git_global_config(void);