From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Philippe Blain via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Luke Shumaker <lukeshu@datawire.io>,
Thomas Koutcher <thomas.koutcher@online.fr>,
James Limbouris <james@digitalmatter.com>,
Philippe Blain <levraiphilippeblain@gmail.com>
Subject: Re: [PATCH 3/9] subtree: add 'die_incompatible_opt' function to reduce duplication
Date: Fri, 21 Oct 2022 18:22:39 +0200 [thread overview]
Message-ID: <221021.86v8oddtuj.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <c890f55f59994231be6114f76f020510eb824453.1666365220.git.gitgitgadget@gmail.com>
On Fri, Oct 21 2022, Philippe Blain via GitGitGadget wrote:
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> 9a3e3ca2ba (subtree: be stricter about validating flags, 2021-04-27)
> added validation code to check that options given to 'git subtree <cmd>'
> made sense with the command being used.
>
> Refactor these checks by adding a 'die_incompatible_opt' function to
> reduce code duplication.
This looks good, but...
> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
> ---
> contrib/subtree/git-subtree.sh | 32 ++++++++++++++++++++------------
> 1 file changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 49ef493ef92..f5eab198c80 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -102,6 +102,14 @@ assert () {
> fi
> }
>
> +# Usage: die_incompatible_opt OPTION COMMAND
> +die_incompatible_opt () {
> + assert test "$#" = 2
> + opt="$1"
> + arg_command="$2"
> + die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
> +}
> +
> main () {
> if test $# -eq 0
> then
> @@ -176,16 +184,16 @@ main () {
> arg_debug=1
> ;;
> --annotate)
> - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
> + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
> arg_split_annotate="$1"
> shift
> ;;
Since this is all in this form I wonder why not (maybe adding some "local" and/or "&&" too while at it):
die_if_other_opt {
assert test "$#" = 3
other="$1"
shift
if test -z "$other"
then
return
fi
[...the rest of your version]
}
Then:
> --no-annotate)
> - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
> + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
Instead of this:
die_if_other_opt "$allow_split" "$opt" "$arg_command"
Or actually just:
die_if_other_opt "$allow_split"
Maybe you disagree, but since the function will see the variables & this
is purely a helper for this getopts parse loop I think it's fine just to
assume we can read "$opt" and "$arg_command" there..., so, urm, maybe just:
test -n "$allow_split" || die_incompatible_opt
? :) Anyway, an easy bike shed, you should go for whatever variant you
prefer :) Thanks for indulging me.
next prev parent reply other threads:[~2022-10-21 16:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-21 15:13 [PATCH 0/9] subtree: fix split and merge after annotated tag was squash-merged Philippe Blain via GitGitGadget
2022-10-21 15:13 ` [PATCH 1/9] test-lib-functions: mark 'test_commit' variables as 'local' Philippe Blain via GitGitGadget
2022-10-21 21:06 ` Junio C Hamano
2022-10-26 21:21 ` Philippe Blain
2022-10-26 21:38 ` Junio C Hamano
2022-10-21 15:13 ` [PATCH 2/9] subtree: use 'git rev-parse --verify [--quiet]' for better error messages Philippe Blain via GitGitGadget
2022-10-21 15:13 ` [PATCH 3/9] subtree: add 'die_incompatible_opt' function to reduce duplication Philippe Blain via GitGitGadget
2022-10-21 16:22 ` Ævar Arnfjörð Bjarmason [this message]
2022-10-26 21:23 ` Philippe Blain
2022-10-21 15:13 ` [PATCH 4/9] subtree: prefix die messages with 'fatal' Philippe Blain via GitGitGadget
2022-10-21 16:30 ` Ævar Arnfjörð Bjarmason
2022-10-26 21:24 ` Philippe Blain
2022-10-21 15:13 ` [PATCH 5/9] subtree: define a variable before its first use in 'find_latest_squash' Philippe Blain via GitGitGadget
2022-10-21 15:13 ` [PATCH 6/9] subtree: use named variables instead of "$@" in cmd_pull Philippe Blain via GitGitGadget
2022-10-21 15:13 ` [PATCH 7/9] subtree: process 'git-subtree-split' trailer in separate function Philippe Blain via GitGitGadget
2022-10-21 15:13 ` [PATCH 8/9] subtree: fix squash merging after annotated tag was squashed merged Philippe Blain via GitGitGadget
2022-10-21 15:13 ` [PATCH 9/9] subtree: fix split " Philippe Blain via GitGitGadget
2022-10-21 16:37 ` Ævar Arnfjörð Bjarmason
2022-10-21 18:24 ` Eric Sunshine
2022-10-26 21:26 ` Philippe Blain
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=221021.86v8oddtuj.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=james@digitalmatter.com \
--cc=levraiphilippeblain@gmail.com \
--cc=lukeshu@datawire.io \
--cc=thomas.koutcher@online.fr \
/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).