From: Junio C Hamano <gitster@pobox.com>
To: Usman Akinyemi <usmanakinyemi202@gmail.com>
Cc: git@vger.kernel.org, christian.couder@gmail.com, ps@pks.im,
shejialuo@gmail.com, johncai86@gmail.com,
Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [RFC PATCH] config: teach `repo_config()` to allow `repo` to be NULL
Date: Thu, 27 Feb 2025 10:46:11 -0800 [thread overview]
Message-ID: <xmqqbjun6xak.fsf@gitster.g> (raw)
In-Reply-To: <20250227175456.1129840-1-usmanakinyemi202@gmail.com> (Usman Akinyemi's message of "Thu, 27 Feb 2025 23:24:34 +0530")
Usman Akinyemi <usmanakinyemi202@gmail.com> writes:
> The `repo` value can be NULL if a builtin command is run outside
> any repository. The current implementation of `repo_config()` will
> fail if `repo` is NULL.
>
> If the `repo` is NULL the `repo_config()` can ignore the repository
> configuration but it should read the other configuration sources like
> the system-side configuration instead of failing.
>
> Teach the `repo_config()` to allow `repo` to be NULL by calling the
> `read_very_early_config()` which read config but only enumerate system
> and global settings.
>
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Mentored-by: Christian Couder <chriscool@tuxfamily.org>
> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
> ---
> config.c | 4 ++++
> config.h | 3 +++
> 2 files changed, 7 insertions(+)
Thanks for tackling this one. The other day I was looking at the
code paths involved and was trying to think of a way to "fix" it at
deeper level than this one, but didn't think of this much simpler
solution.
This is so drastic a change of behaviour that it deserves some
tests, I think.
> diff --git a/config.c b/config.c
> index 36f76fafe5..c5181fd23b 100644
> --- a/config.c
> +++ b/config.c
> @@ -2526,6 +2526,10 @@ void repo_config_clear(struct repository *repo)
>
> void repo_config(struct repository *repo, config_fn_t fn, void *data)
> {
> + if (!repo) {
> + read_very_early_config(fn, data);
> + return;
> + }
> git_config_check_init(repo);
> configset_iter(repo->config, fn, data);
> }
> diff --git a/config.h b/config.h
> index 5c730c4f89..1e5b22dfc4 100644
> --- a/config.h
> +++ b/config.h
> @@ -219,6 +219,9 @@ void read_very_early_config(config_fn_t cb, void *data);
> * repo-specific one; by overwriting, the higher-priority repo-specific
> * value is left at the end).
> *
> + * In cases where the repository variable is NULL, repo_config() will
> + * call read_early_config().
> + *
> * Unlike git_config_from_file(), this function respects includes.
> */
> void repo_config(struct repository *r, config_fn_t fn, void *);
next prev parent reply other threads:[~2025-02-27 18:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 17:54 [RFC PATCH] config: teach `repo_config()` to allow `repo` to be NULL Usman Akinyemi
2025-02-27 18:35 ` Eric Sunshine
2025-02-27 18:46 ` Junio C Hamano [this message]
2025-02-28 10:56 ` Phillip Wood
2025-02-28 18:14 ` Junio C Hamano
2025-02-28 23:56 ` Usman Akinyemi
2025-03-01 19:45 ` Junio C Hamano
2025-03-03 17:37 ` Usman Akinyemi
2025-03-03 18:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbjun6xak.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=johncai86@gmail.com \
--cc=ps@pks.im \
--cc=shejialuo@gmail.com \
--cc=usmanakinyemi202@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).