From: Junio C Hamano <gitster@pobox.com>
To: Roy Eldar <royeldar0@gmail.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: [PATCH v2 0/8] git-submodule.sh: improve parsing of options
Date: Tue, 10 Dec 2024 08:26:49 +0900 [thread overview]
Message-ID: <xmqq1pygo2ti.fsf@gitster.g> (raw)
In-Reply-To: <20241209165009.40653-1-royeldar0@gmail.com> (Roy Eldar's message of "Mon, 9 Dec 2024 18:50:01 +0200")
Roy Eldar <royeldar0@gmail.com> writes:
> When we run "git submodule", the script parses the various options and
> then invokes "git-submodule--helper". Unlike most builtin git commands
> which parse short/long options using parse-options.c, the parsing of
> arguments is completely done within git-submodule.sh; therefore, there
> are some inconsistencies with the rest of the commands, in particular
> the parsing of option arguments given to various options.
>
> Improve the handling of option arguments for both long & short options;
> for example, passing flags such as "--branch=master" or "-j8" now works.
>
> Changes since v1:
>
> - Make variable values always contain the option name.
> - Rename a couple of variables in order to improve consistency.
After reading this, it was confusing to see [1/8] still doing "1 or
empty" boolean, only to be further modified in [7/8]. We prefer to
see a single series stumbling in the middle and changing the course.
Just a tangent.
While a simple wrapper script is generally easier to debug and read
if $verbose variable's value is "--verbose" or "", there is a case
where following this pattern is not a good idea. If an option we
are eventually going to give to the underlying command takes a
value, the value can contain whitespace, and the option and its
value need to be passed as two separate arguments, it is less error
prone to use the "variable only contains the value" approach.
Imagine that submodule--helper takes a "--foo" option with a greeting
message like "hello world" in such a way. We'd want to trigger it
this way:
git submodule--helper --foo "hello world"
as we are assuming that for some reason we need to pass them as two
words, and
git submodule--helper --foo="hello world"
is not an option. In such a case, a wrapper script that takes such
an optional parameter in $foo is easier to write like so
# parse
foo=
while ...
do
case "$opt" in
--foo=*) foo="${1#--foo=}" ;;
--foo) foo=${2?"--foo without value"}; shift ;;
...
esac
shift
done
# interpolate
git submodule--helper ${foo:+--foo "$foo"}
in order to avoid the value given to the option split at $IFS
whitespace. With foo='--foo="hello world"', passing it to the
underlying command would involve use of eval and becomes error
prone.
I am assuming (but I don't use "git submodule" very often, so my
assumption may be way off) that there is no such variable we need to
pass, but if not, we may need to reconsider and use the "variable has
only value of the option" for at least some of them.
> Link to v1:
>
> https://lore.kernel.org/git/20241207135201.2536-1-royeldar0@gmail.com
>
> Roy Eldar (8):
> git-submodule.sh: make some variables boolean
> git-submodule.sh: improve parsing of some long options
> git-submodule.sh: improve parsing of short options
> git-submodule.sh: get rid of isnumber
> git-submodule.sh: get rid of unused variable
> git-submodule.sh: add some comments
> git-submodule.sh: improve variables readability
> git-submodule.sh: rename some variables
>
> git-submodule.sh | 214 +++++++++++++++++++++++------------------------
> 1 file changed, 104 insertions(+), 110 deletions(-)
next prev parent reply other threads:[~2024-12-09 23:26 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-07 13:51 [PATCH 0/3] git-submodule.sh: improve parsing of options Roy Eldar
2024-12-07 13:51 ` [PATCH 1/3] git-submodule.sh: make some variables boolean Roy Eldar
2024-12-07 23:43 ` Junio C Hamano
2024-12-08 0:06 ` Eric Sunshine
2024-12-07 13:52 ` [PATCH 2/3] git-submodule.sh: improve parsing of some long options Roy Eldar
2024-12-07 13:52 ` [PATCH 3/3] git-submodule.sh: improve parsing of short options Roy Eldar
2024-12-08 0:02 ` Junio C Hamano
2024-12-09 16:21 ` Roy E
2024-12-09 16:50 ` [PATCH v2 0/8] git-submodule.sh: improve parsing of options Roy Eldar
2024-12-09 16:50 ` [PATCH v2 1/8] git-submodule.sh: make some variables boolean Roy Eldar
2024-12-09 16:50 ` [PATCH v2 2/8] git-submodule.sh: improve parsing of some long options Roy Eldar
2024-12-09 16:50 ` [PATCH v2 3/8] git-submodule.sh: improve parsing of short options Roy Eldar
2024-12-09 16:50 ` [PATCH v2 4/8] git-submodule.sh: get rid of isnumber Roy Eldar
2024-12-09 16:50 ` [PATCH v2 5/8] git-submodule.sh: get rid of unused variable Roy Eldar
2024-12-09 16:50 ` [PATCH v2 6/8] git-submodule.sh: add some comments Roy Eldar
2024-12-09 16:50 ` [PATCH v2 7/8] git-submodule.sh: improve variables readability Roy Eldar
2024-12-09 16:50 ` [PATCH v2 8/8] git-submodule.sh: rename some variables Roy Eldar
2024-12-09 23:26 ` Junio C Hamano [this message]
2024-12-10 0:50 ` [PATCH v2 0/8] git-submodule.sh: improve parsing of options Junio C Hamano
2024-12-10 18:11 ` Roy E
2024-12-11 0:02 ` Junio C Hamano
2024-12-11 6:13 ` Roy E
2024-12-11 6:16 ` Junio C Hamano
2024-12-10 18:44 ` [PATCH v3 0/7] " Roy Eldar
2024-12-10 18:44 ` [PATCH v3 1/7] git-submodule.sh: improve parsing of some long options Roy Eldar
2024-12-10 18:44 ` [PATCH v3 2/7] git-submodule.sh: improve parsing of short options Roy Eldar
2024-12-10 18:44 ` [PATCH v3 3/7] git-submodule.sh: get rid of isnumber Roy Eldar
2024-12-10 18:44 ` [PATCH v3 4/7] git-submodule.sh: get rid of unused variable Roy Eldar
2024-12-10 18:44 ` [PATCH v3 5/7] git-submodule.sh: add some comments Roy Eldar
2024-12-10 18:44 ` [PATCH v3 6/7] git-submodule.sh: improve variables readability Roy Eldar
2024-12-11 0:14 ` Junio C Hamano
2024-12-11 6:21 ` Roy E
2024-12-11 1:56 ` Đoàn Trần Công Danh
2024-12-11 6:09 ` Junio C Hamano
2024-12-10 18:44 ` [PATCH v3 7/7] git-submodule.sh: rename some variables Roy Eldar
2024-12-11 6:32 ` [PATCH v4 0/7] git-submodule.sh: improve parsing of options Roy Eldar
2024-12-11 6:32 ` [PATCH v4 1/7] git-submodule.sh: improve parsing of some long options Roy Eldar
2024-12-11 6:32 ` [PATCH v4 2/7] git-submodule.sh: improve parsing of short options Roy Eldar
2024-12-11 6:32 ` [PATCH v4 3/7] git-submodule.sh: get rid of isnumber Roy Eldar
2024-12-11 6:32 ` [PATCH v4 4/7] git-submodule.sh: get rid of unused variable Roy Eldar
2024-12-11 6:32 ` [PATCH v4 5/7] git-submodule.sh: add some comments Roy Eldar
2024-12-11 6:32 ` [PATCH v4 6/7] git-submodule.sh: improve variables readability Roy Eldar
2024-12-11 6:32 ` [PATCH v4 7/7] git-submodule.sh: rename some variables Roy Eldar
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=xmqq1pygo2ti.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=royeldar0@gmail.com \
--cc=sunshine@sunshineco.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).