git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Derrick Stolee <stolee@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>
Cc: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH] scalar: accept -C and -c options before the subcommand
Date: Fri, 28 Jan 2022 14:52:26 -0500	[thread overview]
Message-ID: <2150a170-bf02-f510-3995-c103650ad8fc@gmail.com> (raw)
In-Reply-To: <220128.8635l7d7y6.gmgdl@evledraar.gmail.com>

On 1/28/2022 1:21 PM, Ævar Arnfjörð Bjarmason wrote:
> 
> On Fri, Jan 28 2022, Johannes Schindelin wrote:
> 
>> On Thu, 27 Jan 2022, Derrick Stolee wrote:
>>
>>> The biggest benefits of using handle_options() is for other pre-command
>>> options such as --exec-path, which I use on a regular basis when testing
>>> new functionality.
>>>
>>> There are other options in handle_options() that might not be
>>> appropriate, or might be incorrect if we just make handle_options()
>>> non-static. For example, `scalar --list-cmds=parseopt` wouldn't show the
>>> scalar commands and would instead show the git commands.
>>
>> Right, and since `handle_options()` lives in the same file as `git`'s
>> `cmd_main()` function, we would not only have to disentangle options that
>> work only for `git` from those that would also work for `scalar`, but we
>> would have to extract the `handle_options()` function into a separate
>> file.
>>
>> And while at it, a tangent someone with infinite time on their hands might
>> suggest is: why not convert `handle_options()` to the `parse_options()`
>> machinery? Which would of course solve one issue by adding several new
>> ones. Don't get me wrong: I would find it useful to convert
>> `git.c:handle_options()` to a function in `libgit.a` which uses the
>> `parse_options()` machinery. It'll just require a lot of time, and I do
>> not see enough benefit that would make it worth embarking on that
>> particular journey.
>>
>> But since I had a look at `handle_options()` anyway, I might just as well
>> summarize my insights about how applicable the supported options are for
>> `scalar` here:
>> [...]
>> # Detrimental
>>
>>   --exec-path
>>
>> 	Since `scalar` is tightly coupled to a specific Git version, it
>> 	would cause much more harm than benefit to encourage users to use
>> 	a different Git version by offering them this option.
> 
> So just to clarify, do you and Stolee disagree about scalar supporting
> --exec-path, per his comments above?

I think it would be nice, but it's also not a blocker for me.

> In this case I don't mind much, but speaking generally I see you and
> Stolee tying yourselves in knots again about scalar being in contrib so
> we shouldn't use libgit.
> 
> It already uses libgit, there's even (last I checked) at least one
> function in it only used directly by the scalar code.

My concern is not that we shouldn't use libgit (because we do) but that
we shouldn't make significant changes to libgit.a only for Scalar's
benefit until it is incorporated in a more final way.

In my opinion, well-architected code is code that is easy to delete.
Until we have Scalar mostly feature-complete and can make a decision
about it living in the Git tree long-term (and _where_ it resides), I
would like to have the following property: If I were to revert all
commits that touch contrib/scalar/ and squash them into a single commit,
then we would have a bunch of file deletions and a very small set of
edits to the Makefile. I don't know how much the ship has sailed there
already, but keeping the size of that "revert diff" small means that we
are keeping the coupling low during this review process.
 
> I don't remember anyone having any objection to scalar using libgit
> code, or even that there's libgit code just to help it along. That's a
> self-imposed limitation you two seem to have invented.
> 
> Personally I find a patch like the below much easier to review. It's the
> parts that aren't easy to review boilerplate are all things that we have
> in-tree already.
> 
> Whereas proposing a new way to parse -c or -C will lead (at least me) to
> carefully eyeballing that new implementation, looking at how it differs
> (if at all) from the existing one, wondering why the i18n strings are
> subtly different etc (I saw one reason is that since the code was
> copy/pasted initially the git.c version was updated, but your patch
> wasn't updated to copy it).

> diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c
> index 1ce9c2b00e8..ee793ff6ccc 100644
> --- a/contrib/scalar/scalar.c
> +++ b/contrib/scalar/scalar.c

> diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c
> index 1ce9c2b00e8..ee793ff6ccc 100644
> --- a/contrib/scalar/scalar.c
> +++ b/contrib/scalar/scalar.c

Was this diff double-copied or something?

> +	while (argc > 1 && *argv[0] == '-') {
> +		int show_usage = 0;
> +
> +		if (gity_handle_options(&argv, &argc, NULL, &show_usage)) {
> +			(argv)++;
> +			(argc)--;
> +
> +			if (show_usage)
> +				goto usage;
> +		} else {
> +			break;
> +		}
> +	}
> +
> +	if (argc) {

This loop seemed a tad cumbersome for something calling a helper
method, BUT....

> @@ -322,6 +295,10 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
>  			} else {
>  				exit(list_cmds(cmd));
>  			}
> +		} else if (gity_handle_options(argv, argc, envchanged,
> +					       &show_usage)) {
> +			if (show_usage)
> +				usage(git_usage_string);

...by checking this at the end of your loop here, you have solved
the concern I was talking about with something like

	git --no-pager -C <X> status

having the -C parsing fail because it doesn't recognize --no-pager.

I think this patch you present here would be a good approach to
start transitioning options out of handle_options(), perhaps one
at a time.

But due to my stated goal of "let's not modify things in libgit.a
for Scalar unless absolutely necessary", this approach should be
delayed until at least Scalar is more final.

Thanks,
-Stolee

  reply	other threads:[~2022-01-28 19:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26 11:15 [PATCH] scalar: accept -C and -c options before the subcommand Johannes Schindelin via GitGitGadget
2022-01-26 20:53 ` Taylor Blau
2022-01-28 11:43   ` Johannes Schindelin
2022-01-27  2:55 ` Ævar Arnfjörð Bjarmason
2022-01-27 14:46   ` Derrick Stolee
2022-01-28 11:27     ` Johannes Schindelin
2022-01-28 18:21       ` Ævar Arnfjörð Bjarmason
2022-01-28 19:52         ` Derrick Stolee [this message]
2022-01-29  6:39           ` Ævar Arnfjörð Bjarmason
2022-01-28 19:37       ` Derrick Stolee
2022-01-28 18:05     ` Junio C Hamano
2022-01-28 19:38       ` Derrick Stolee
2022-01-28 14:31 ` [PATCH v2] " Johannes Schindelin via GitGitGadget
2022-01-28 19:40   ` Derrick Stolee

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2150a170-bf02-f510-3995-c103650ad8fc@gmail.com \
    --to=stolee@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=me@ttaylorr.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).