From: Usman Akinyemi <usmanakinyemi202@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Phillip Wood <phillip.wood123@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: Sat, 1 Mar 2025 05:26:55 +0530 [thread overview]
Message-ID: <CAPSxiM-fzKUtvvf-DB2=VaGznr9utyb6zaKU5onxpy49KPChUA@mail.gmail.com> (raw)
In-Reply-To: <xmqqbjum2ayc.fsf@gitster.g>
On Fri, Feb 28, 2025 at 11:44 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> 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.
>
Hello,
> > 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.
Yeah, these all are true. Also, "git for-each-repo" and many other commands
seems not to make use of rep_config() or git_config(). I think this change and
functions are good for command marked RUN_SETUP since their behaviour
is pretty straight forward. I think, we might want to use another approach for
other commands that are not marked RUN_SETUP if we decide to remove
the_repository from them.
>
> 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.
Yeah, I understand. I believe these change we are trying to make to
builtin commands that are marked RUN_SETUP is a good goal due to how
they work, what do you think ?
Also, about the testing, I was thinking of using the clar framework or the
test-tool, do you have any in mind ?
Thank you.
next prev parent reply other threads:[~2025-02-28 23:57 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
2025-02-28 23:56 ` Usman Akinyemi [this message]
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='CAPSxiM-fzKUtvvf-DB2=VaGznr9utyb6zaKU5onxpy49KPChUA@mail.gmail.com' \
--to=usmanakinyemi202@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johncai86@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
--cc=shejialuo@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).