From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: Usman Akinyemi <usmanakinyemi202@gmail.com>,
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: Fri, 28 Feb 2025 10:14:35 -0800 [thread overview]
Message-ID: <xmqqbjum2ayc.fsf@gitster.g> (raw)
In-Reply-To: <4e21312d-0d9a-404a-a2e0-0e2fcc681ad6@gmail.com> (Phillip Wood's message of "Fri, 28 Feb 2025 10:56:23 +0000")
Phillip Wood <phillip.wood123@gmail.com> writes:
> Thanks for working on this, I like the idea but looking at
> read_very_early_config() it sets "opts.ignore_cmdline = 1" which means
> that this will ignore any config options passed with "git -c
> key=value". I think it would be better to call config_with_options()
> with the appropriate options directly.
hmph.
> For this to work all the commands that run outside a repository would
> have to read the config via repo_config(), and take care not to call
> any of the repo_config_get_*() functions. They mostly seem to do that
> but "git for-each-repo" calls repo_config_get_string_multi() - it
> should be easy enough to convert that to a callback when that command
> is updated to stop using "the_repository"
Well the only reason why we want to allow NULL in repo_config()
calls is to accomodate this pattern, if I am reading the discussion
correctly.
* A command that wants to run in a repository (i.e. marked with
RUN_SETUP, not RUN_SETUP_GENTLY) is invoked with "-h" and outside
the repository.
* cmd_foo() is called with "-h" option in argv[]; repo is set to
NULL.
* The typical start-up sequence for any builtin cmd_foo() is to
read the configuration and then call parseopt, and the latter is
how "git foo -h" is handled.
* Historically, the "call the configuration" was done by making a
call to git_config(), which used the_repository [*]. But recent
trend is to use the repo passed down to cmd_foo() instead, and
replacing git_config() with repo_config() blindly would break
unless repo_config() is prepared to take NULL.
So, any command that requires to be in a repository would not go
beyond its call to parse_options() when called with repo==NULL.
Either it would have already died inside getup_git_directory() when
"-h" is not given, or parse_options() would have gave the usage
string and exited.
For commands like "for-each-repo" that itself wants to be able to
run outside a repository by marking itself as RUN_SETUP_GENTLY,
they do have to update the code after the parse_options()
themselves, of course, but I view it as a separate issue from this
"we make git_config() as the first thing in everything---we want
to replace it with repo_config()" patch.
Thanks.
[Footnote]
* I personally think that it is an unhealthy fundamentalism to try
eradicating the use of the_repository even from the top-level
calls of cmd_foo() functions, which are like traditional main().
They are never meant to be reused as a subroutine that can work
on an arbitrary repository from any arbitrary codepaths. The
special repository instance, the_repository, is set up to be
suitable to work in the current repository, if exists, and gives
a reasonable fallback behaviour when we are not inside a
repository, which behaves exactly how we want it to behave there.
The more library-ish helper functions (I am talking about
distinction between what is in say builtin/diff.c and diff-lib.c
here and referring to the latter) are totally different matter,
of course. They are meant to be reused and they should be made
to work on an arbitrary repository from arbitrary codepaths,
hence reducing the reliance on the_repository is a good goal for
them to aim at.
next prev parent reply other threads:[~2025-02-28 18:14 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
2025-02-28 10:56 ` Phillip Wood
2025-02-28 18:14 ` Junio C Hamano [this message]
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=xmqqbjum2ayc.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=phillip.wood123@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).