From: Roy Eldar <royeldar0@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Đoàn Trần Công Danh" <congdanhqx@gmail.com>,
"Roy Eldar" <royeldar0@gmail.com>
Subject: [PATCH v4 6/7] git-submodule.sh: improve variables readability
Date: Wed, 11 Dec 2024 08:32:33 +0200 [thread overview]
Message-ID: <20241211063234.7610-7-royeldar0@gmail.com> (raw)
In-Reply-To: <20241211063234.7610-1-royeldar0@gmail.com>
When git-submodule.sh parses various options and switches, it sets some
variables to values; the variables in turn affect the options given to
git-submodule--helper.
Currently, variables which correspond to switches have boolean values
(for example, whenever "--force" is passed, force=1), while variables
which correspond to options which take arguments have string values that
sometimes contain the option name and sometimes only the option value.
Set all of the variables to strings which contain the option name (e.g.
force="--force" rather than force=1); this has a couple of advantages:
it improves consistency, readability and debuggability.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Roy Eldar <royeldar0@gmail.com>
---
git-submodule.sh | 213 +++++++++++++++++++++--------------------------
1 file changed, 95 insertions(+), 118 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index ee86e4de46..6df25efc48 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -52,6 +52,10 @@ single_branch=
jobs=
recommend_shallow=
filter=
+deinit_all=
+default=
+summary_limit=
+for_status=
#
# Add a new submodule to the working tree, .gitmodules and the index
@@ -63,37 +67,33 @@ filter=
cmd_add()
{
# parse $args after "submodule ... add".
- reference_path=
while test $# -ne 0
do
case "$1" in
-b | --branch)
case "$2" in '') usage ;; esac
- branch=$2
+ branch="--branch=$2"
shift
;;
- -b*)
- branch="${1#-b}"
- ;;
- --branch=*)
- branch="${1#--branch=}"
+ -b* | --branch=*)
+ branch="$1"
;;
-f | --force)
force=$1
;;
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--progress)
- progress=1
+ progress=$1
;;
--reference)
case "$2" in '') usage ;; esac
- reference_path=$2
+ reference="--reference=$2"
shift
;;
--reference=*)
- reference_path="${1#--reference=}"
+ reference="$1"
;;
--ref-format)
case "$2" in '') usage ;; esac
@@ -104,15 +104,15 @@ cmd_add()
ref_format="$1"
;;
--dissociate)
- dissociate=1
+ dissociate=$1
;;
--name)
case "$2" in '') usage ;; esac
- custom_name=$2
+ custom_name="--name=$2"
shift
;;
--name=*)
- custom_name="${1#--name=}"
+ custom_name="$1"
;;
--depth)
case "$2" in '') usage ;; esac
@@ -120,7 +120,7 @@ cmd_add()
shift
;;
--depth=*)
- depth=$1
+ depth="$1"
;;
--)
shift
@@ -142,14 +142,14 @@ cmd_add()
fi
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add \
- ${quiet:+--quiet} \
- ${force:+--force} \
- ${progress:+"--progress"} \
- ${branch:+--branch "$branch"} \
- ${reference_path:+--reference "$reference_path"} \
+ $quiet \
+ $force \
+ $progress \
+ ${branch:+"$branch"} \
+ ${reference:+"$reference"} \
${ref_format:+"$ref_format"} \
- ${dissociate:+--dissociate} \
- ${custom_name:+--name "$custom_name"} \
+ $dissociate \
+ ${custom_name:+"$custom_name"} \
${depth:+"$depth"} \
-- \
"$@"
@@ -168,10 +168,10 @@ cmd_foreach()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--recursive)
- recursive=1
+ recursive=$1
;;
-*)
usage
@@ -184,8 +184,8 @@ cmd_foreach()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach \
- ${quiet:+--quiet} \
- ${recursive:+--recursive} \
+ $quiet \
+ $recursive \
-- \
"$@"
}
@@ -202,7 +202,7 @@ cmd_init()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--)
shift
@@ -219,7 +219,7 @@ cmd_init()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init \
- ${quiet:+--quiet} \
+ $quiet \
-- \
"$@"
}
@@ -230,7 +230,6 @@ cmd_init()
cmd_deinit()
{
# parse $args after "submodule ... deinit".
- deinit_all=
while test $# -ne 0
do
case "$1" in
@@ -238,10 +237,10 @@ cmd_deinit()
force=$1
;;
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--all)
- deinit_all=t
+ deinit_all=$1
;;
--)
shift
@@ -258,9 +257,9 @@ cmd_deinit()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit \
- ${quiet:+--quiet} \
- ${force:+--force} \
- ${deinit_all:+--all} \
+ $quiet \
+ $force \
+ $deinit_all \
-- \
"$@"
}
@@ -277,31 +276,31 @@ cmd_update()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
-v|--verbose)
- quiet=0
+ quiet=
;;
--progress)
- progress=1
+ progress=$1
;;
-i|--init)
- init=1
+ init=$1
;;
--require-init)
- require_init=1
+ require_init=$1
;;
--remote)
- remote=1
+ remote=$1
;;
-N|--no-fetch)
- nofetch=1
+ nofetch=$1
;;
-f|--force)
force=$1
;;
-r|--rebase)
- rebase=1
+ rebase=$1
;;
--ref-format)
case "$2" in '') usage ;; esac
@@ -320,22 +319,19 @@ cmd_update()
reference="$1"
;;
--dissociate)
- dissociate=1
+ dissociate=$1
;;
-m|--merge)
- merge=1
+ merge=$1
;;
--recursive)
- recursive=1
+ recursive=$1
;;
--checkout)
- checkout=1
- ;;
- --recommend-shallow)
- recommend_shallow="--recommend-shallow"
+ checkout=$1
;;
- --no-recommend-shallow)
- recommend_shallow="--no-recommend-shallow"
+ --recommend-shallow|--no-recommend-shallow)
+ recommend_shallow=$1
;;
--depth)
case "$2" in '') usage ;; esac
@@ -343,24 +339,18 @@ cmd_update()
shift
;;
--depth=*)
- depth=$1
+ depth="$1"
;;
-j|--jobs)
case "$2" in '') usage ;; esac
jobs="--jobs=$2"
shift
;;
- -j*)
- jobs="--jobs=${1#-j}"
- ;;
- --jobs=*)
- jobs=$1
+ -j*|--jobs=*)
+ jobs="$1"
;;
- --single-branch)
- single_branch="--single-branch"
- ;;
- --no-single-branch)
- single_branch="--no-single-branch"
+ --single-branch|--no-single-branch)
+ single_branch=$1
;;
--filter)
case "$2" in '') usage ;; esac
@@ -385,22 +375,21 @@ cmd_update()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
- ${quiet:+--quiet} \
- ${force:+--force} \
- ${progress:+"--progress"} \
- ${remote:+--remote} \
- ${recursive:+--recursive} \
- ${init:+--init} \
- ${nofetch:+--no-fetch} \
- ${rebase:+--rebase} \
- ${merge:+--merge} \
- ${checkout:+--checkout} \
+ $quiet \
+ $force \
+ $progress \
+ $remote \
+ $recursive \
+ $init \
+ $nofetch \
+ $rebase \
+ $merge \
+ $checkout \
${ref_format:+"$ref_format"} \
${reference:+"$reference"} \
- ${dissociate:+"--dissociate"} \
+ $dissociate \
${depth:+"$depth"} \
- ${require_init:+--require-init} \
- ${dissociate:+"--dissociate"} \
+ $require_init \
$single_branch \
$recommend_shallow \
$jobs \
@@ -415,9 +404,6 @@ cmd_update()
# $@ = requested path
#
cmd_set_branch() {
- default=
- branch=
-
# parse $args after "submodule ... set-branch".
while test $# -ne 0
do
@@ -426,18 +412,15 @@ cmd_set_branch() {
# we don't do anything with this but we need to accept it
;;
-d|--default)
- default=1
+ default=$1
;;
-b|--branch)
case "$2" in '') usage ;; esac
- branch=$2
+ branch="--branch=$2"
shift
;;
- -b*)
- branch="${1#-b}"
- ;;
- --branch=*)
- branch="${1#--branch=}"
+ -b*|--branch=*)
+ branch="$1"
;;
--)
shift
@@ -454,9 +437,9 @@ cmd_set_branch() {
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch \
- ${quiet:+--quiet} \
- ${branch:+--branch "$branch"} \
- ${default:+--default} \
+ $quiet \
+ ${branch:+"$branch"} \
+ $default \
-- \
"$@"
}
@@ -472,7 +455,7 @@ cmd_set_url() {
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--)
shift
@@ -489,7 +472,7 @@ cmd_set_url() {
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url \
- ${quiet:+--quiet} \
+ $quiet \
-- \
"$@"
}
@@ -503,32 +486,26 @@ cmd_set_url() {
# $@ = [commit (default 'HEAD'),] requested paths (default all)
#
cmd_summary() {
- summary_limit=-1
- for_status=
-
# parse $args after "submodule ... summary".
while test $# -ne 0
do
case "$1" in
--cached)
- cached=1
+ cached=$1
;;
--files)
- files="$1"
+ files=$1
;;
--for-status)
- for_status="$1"
+ for_status=$1
;;
-n|--summary-limit)
case "$2" in '') usage ;; esac
- summary_limit="$2"
+ summary_limit="--summary-limit=$2"
shift
;;
- -n*)
- summary_limit="${1#-n}"
- ;;
- --summary-limit=*)
- summary_limit="${1#--summary-limit=}"
+ -n*|--summary-limit=*)
+ summary_limit="$1"
;;
--)
shift
@@ -545,10 +522,10 @@ cmd_summary() {
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary \
- ${files:+--files} \
- ${cached:+--cached} \
- ${for_status:+--for-status} \
- ${summary_limit:+-n "$summary_limit"} \
+ $files \
+ $cached \
+ $for_status \
+ ${summary_limit:+"$summary_limit"} \
-- \
"$@"
}
@@ -569,13 +546,13 @@ cmd_status()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--cached)
- cached=1
+ cached=$1
;;
--recursive)
- recursive=1
+ recursive=$1
;;
--)
shift
@@ -592,9 +569,9 @@ cmd_status()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status \
- ${quiet:+--quiet} \
- ${cached:+--cached} \
- ${recursive:+--recursive} \
+ $quiet \
+ $cached \
+ $recursive \
-- \
"$@"
}
@@ -611,11 +588,11 @@ cmd_sync()
do
case "$1" in
-q|--quiet)
- quiet=1
+ quiet=$1
shift
;;
--recursive)
- recursive=1
+ recursive=$1
shift
;;
--)
@@ -632,8 +609,8 @@ cmd_sync()
done
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync \
- ${quiet:+--quiet} \
- ${recursive:+--recursive} \
+ $quiet \
+ $recursive \
-- \
"$@"
}
@@ -656,10 +633,10 @@ do
command=$1
;;
-q|--quiet)
- quiet=1
+ quiet=$1
;;
--cached)
- cached=1
+ cached=$1
;;
--)
break
--
2.30.2
next prev parent reply other threads:[~2024-12-11 6:33 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 ` [PATCH v2 0/8] git-submodule.sh: improve parsing of options Junio C Hamano
2024-12-10 0:50 ` 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 ` Roy Eldar [this message]
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=20241211063234.7610-7-royeldar0@gmail.com \
--to=royeldar0@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=congdanhqx@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).