[PATCH 0/11] Usage string clean-up

STALE3735d

16 messages, 4 authors, 2016-06-15 · open the first message on its own page

[PATCH 0/11] Usage string clean-up

From: <hidden>
Date: 2016-06-15 22:42:14

Hi,

This is a redone version of the usage string clean-up patch series. It
should apply cleanly on top of the current 'pu' branch.

This version is supposed to get the details right.

The scripts are supposed to set the variable USAGE to some suitable
value before they source git-sh-setup. Optionally they can also set
LONG_USAGE to a more descriptive help message.

* --help makes the scripts print the (long) usage string and exit
  cleanly.
* Unrecognized options prints the usage string and exits non-cleanly.
* The printed string is of the form "Usage: $0 options". The "Usage:
  $0 " part can easily be changed by changing git-sh-setup.sh

The real value of this series is that all commands prints a usage
message when they get '--help'.

I have left *.perl for a later patch.

 git-add.sh           |   13 +++----------
 git-am.sh            |   10 +++-------
 git-applymbox.sh     |    6 +-----
 git-applypatch.sh    |    4 ++++
 git-checkout.sh      |    6 ++----
 git-cherry.sh        |   13 +++++--------
 git-clone.sh         |    2 +-
 git-commit.sh        |    5 +----
 git-count-objects.sh |    4 +++-
 git-fetch.sh         |    5 +++++
 git-format-patch.sh  |   25 ++++++++-----------------
 git-grep.sh          |    7 +++++--
 git-lost-found.sh    |   10 +++++++++-
 git-merge.sh         |    6 ++----
 git-prune.sh         |    3 ++-
 git-pull.sh          |   13 ++-----------
 git-push.sh          |    7 ++-----
 git-rebase.sh        |    5 +++--
 git-repack.sh        |    2 ++
 git-request-pull.sh  |   12 +++++-------
 git-reset.sh         |    6 ++----
 git-resolve.sh       |    6 ++----
 git-revert.sh        |   19 +++++--------------
 git-tag.sh           |   14 +++-----------
 git-verify-tag.sh    |   14 ++++++++------
 25 files changed, 88 insertions(+), 129 deletions(-)

- Fredrik

[PATCH 8/11] git-lost-found: Usage string clean-up, emit usage string at incorrect invocation

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-lost-found.sh |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

240de5191779f0637fb339a80a76770ee35f5a68
diff --git a/git-lost-found.sh b/git-lost-found.sh
index 2beec2a..ba6d587 100755
--- a/git-lost-found.sh
+++ b/git-lost-found.sh
@@ -1,6 +1,14 @@
 #!/bin/sh
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+USAGE=''
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
+if [ "$#" != "0" ]
+then
+    usage
+fi
+
 laf="$GIT_DIR/lost-found"
 rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
 
-- 
0.99.9.GIT

[PATCH 4/11] git-am: Usage string clean-up

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-am.sh |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

243b906a6786cd7401285cacaf9ade994ff83db8
diff --git a/git-am.sh b/git-am.sh
index 6ed527c..39f2552 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -1,14 +1,10 @@
 #!/bin/sh
 #
 #
-. git-sh-setup
 
-usage () {
-    echo >&2 "usage: $0 [--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>"
-    echo >&2 "	or, when resuming"
-    echo >&2 "	$0 [--skip | --resolved]"
-    exit 1;
-}
+USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>
+  or, when resuming [--skip | --resolved]'
+. git-sh-setup
 
 stop_here () {
     echo "$1" >"$dotest/next"
-- 
0.99.9.GIT

[PATCH 3/11] git-revert: Usage string clean-up

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-revert.sh |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

16ecbff0d2e6cf51ff92f081ad66b5bcc3883e31
diff --git a/git-revert.sh b/git-revert.sh
index 9d499c4..63d201b 100755
--- a/git-revert.sh
+++ b/git-revert.sh
@@ -3,29 +3,20 @@
 # Copyright (c) 2005 Linus Torvalds
 # Copyright (c) 2005 Junio C Hamano
 #
-. git-sh-setup
 
 case "$0" in
 *-revert* )
 	test -t 0 && edit=-e
-	me=revert ;;
+	me=revert
+	USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
 *-cherry-pick* )
 	edit=
-	me=cherry-pick ;;
+	me=cherry-pick
+	USAGE='[--edit] [-n] [-r] <commit-ish>'  ;;
 * )
 	die "What are you talking about?" ;;
 esac
-
-usage () {
-	case "$me" in
-	cherry-pick)
-		die "usage git $me [--edit] [-n] [-r] <commit-ish>"
-		;;
-	revert)
-		die "usage git $me [--edit | --no-edit] [-n] <commit-ish>"
-		;;
-	esac
-}
+. git-sh-setup
 
 no_commit= replay=
 while case "$#" in 0) break ;; esac
-- 
0.99.9.GIT

[PATCH 2/11] git-verify-tag: Usage string clean-up, emit usage string at incorrect invocation

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-verify-tag.sh |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

e1bab3098c4926a09cb74dc767d03fd0f3bf8343
diff --git a/git-verify-tag.sh b/git-verify-tag.sh
index 1f44da5..726b1e7 100755
--- a/git-verify-tag.sh
+++ b/git-verify-tag.sh
@@ -1,11 +1,13 @@
 #!/bin/sh
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
-
-die () {
-    echo >&2 "$*"
-    exit 1
-}
+USAGE='<tag>'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
+if [ "$#" != "1" ]
+then
+  usage
+fi
 
 type="$(git-cat-file -t "$1" 2>/dev/null)" ||
 	die "$1: no such object."
-- 
0.99.9.GIT

[PATCH 1/11] Trivial usage string clean-up

From: <hidden>
Date: 2016-06-15 22:42:14


Signed-off-by: Fredrik Kuivinen <redacted>

---

This patch contains all 'trivial' changes in this series. In
particular, there are no argument parsing changes here.

 git-add.sh           |   13 +++----------
 git-applymbox.sh     |    6 +-----
 git-checkout.sh      |    6 ++----
 git-clone.sh         |    2 +-
 git-commit.sh        |    5 +----
 git-format-patch.sh  |   25 ++++++++-----------------
 git-grep.sh          |    7 +++++--
 git-merge.sh         |    6 ++----
 git-pull.sh          |   13 ++-----------
 git-push.sh          |    7 ++-----
 git-request-pull.sh  |   12 +++++-------
 git-reset.sh         |    6 ++----
 git-resolve.sh       |    6 ++----
 git-tag.sh           |   14 +++-----------
 14 files changed, 39 insertions(+), 89 deletions(-)

50fb9150eb63cd5a4aebeae401f771bd8d1827aa
diff --git a/git-add.sh b/git-add.sh
index fdec86d..f719b4b 100755
--- a/git-add.sh
+++ b/git-add.sh
@@ -1,13 +1,8 @@
 #!/bin/sh
 
-die () {
-    echo >&2 "$*"
-    exit 1
-}
-
-usage() {
-    die "usage: git add [-n] [-v] <file>..."
-}
+USAGE='[-n] [-v] <file>...'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
 
 show_only=
 verbose=
@@ -29,8 +24,6 @@ while : ; do
   shift
 done
 
-GIT_DIR=$(git-rev-parse --git-dir) || exit
-
 if test -f "$GIT_DIR/info/exclude"
 then
 	git-ls-files -z \
diff --git a/git-applymbox.sh b/git-applymbox.sh
index c686cc8..61c8c02 100755
--- a/git-applymbox.sh
+++ b/git-applymbox.sh
@@ -18,13 +18,9 @@
 ##
 ## git-am is supposed to be the newer and better tool for this job.
 
+USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]'
 . git-sh-setup
 
-usage () {
-    echo >&2 "applymbox [-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]"
-    exit 1
-}
-
 keep_subject= query_apply= continue= utf8= resume=t
 while case "$#" in 0) break ;; esac
 do
diff --git a/git-checkout.sh b/git-checkout.sh
index 4cf30e2..f241d4b 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -1,9 +1,7 @@
 #!/bin/sh
-. git-sh-setup
 
-usage () {
-    die "usage: git checkout [-f] [-b <new_branch>] [<branch>] [<paths>...]"
-}
+USAGE='[-f] [-b <new_branch>] [<branch>] [<paths>...]'
+. git-sh-setup
 
 old=$(git-rev-parse HEAD)
 new=
diff --git a/git-clone.sh b/git-clone.sh
index 699205e..4a7aeef 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -9,7 +9,7 @@
 unset CDPATH
 
 usage() {
-	echo >&2 "* git clone [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
+	echo >&2 "Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
 	exit 1
 }
 
diff --git a/git-commit.sh b/git-commit.sh
index 3d250ec..7e39c10 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -3,12 +3,9 @@
 # Copyright (c) 2005 Linus Torvalds
 #
 
+USAGE='[-a] [-s] [-v | --no-verify]  [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
 . git-sh-setup
 
-usage () {
-	die 'git commit [-a] [-s] [-v | --no-verify]  [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
-}
-
 all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
 while case "$#" in 0) break;; esac
 do
diff --git a/git-format-patch.sh b/git-format-patch.sh
index 921feee..01508e3 100755
--- a/git-format-patch.sh
+++ b/git-format-patch.sh
@@ -3,19 +3,8 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-. git-sh-setup
-
-# Force diff to run in C locale.
-LANG=C LC_ALL=C
-export LANG LC_ALL
-
-usage () {
-    echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
-    [--check] [--signoff] [-<diff options>...]
-    [--help]
-    ( from..to ... | upstream [ our-head ] )
-
-Prepare each commit with its patch since our-head forked from upstream,
+USAGE='[-n | -k] [-o <dir> | --stdout] [--signoff] [--check] [--mbox] [--diff-options] <upstream> [<our-head>]'
+LONG_USAGE='Prepare each commit with its patch since our-head forked from upstream,
 one file per patch, for e-mail submission.  Each output file is
 numbered sequentially from 1, and uses the first line of the commit
 message (massaged for pathname safety) as the filename.
@@ -28,10 +17,12 @@ as "[PATCH N/M] Subject", unless you hav
 
 When --mbox is specified, the output is formatted to resemble
 UNIX mailbox format, and can be concatenated together for processing
-with applymbox.
-'
-    exit 1
-}
+with applymbox.'
+. git-sh-setup
+
+# Force diff to run in C locale.
+LANG=C LC_ALL=C
+export LANG LC_ALL
 
 diff_opts=
 LF='
diff --git a/git-grep.sh b/git-grep.sh
index 44c1613..2ed8e95 100755
--- a/git-grep.sh
+++ b/git-grep.sh
@@ -3,6 +3,10 @@
 # Copyright (c) Linus Torvalds, 2005
 #
 
+USAGE='<option>... <pattern> <path>...'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
 pattern=
 flags=()
 git_flags=()
@@ -40,8 +44,7 @@ while : ; do
 	shift
 done
 [ "$pattern" ] || {
-	echo >&2 "usage: 'git grep <pattern> [pathspec*]'"
-	exit 1
+	usage
 }
 git-ls-files -z "${git_flags[@]}" "$@" |
 	xargs -0 grep "${flags[@]}" -e "$pattern"
diff --git a/git-merge.sh b/git-merge.sh
index a221daa..bed1ffd 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -3,15 +3,13 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
+
+USAGE='[-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+'
 . git-sh-setup
 
 LF='
 '
 
-usage () {
-    die "git-merge [-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+"
-}
-
 all_strategies='recursive octopus resolve stupid ours'
 default_strategies='recursive'
 use_strategies=
diff --git a/git-pull.sh b/git-pull.sh
index 3a13984..0991d5f 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -4,19 +4,10 @@
 #
 # Fetch one or more remote refs and merge it/them into the current HEAD.
 
+USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'
+LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
 . git-sh-setup
 
-usage () {
-    echo >&2 "usage: $0"' [-n] [--no-commit] [--no-summary] [--help]
-    [-s strategy]...
-    [<fetch-options>]
-    <repo> <head>...
-
-Fetch one or more remote refs and merge it/them into the current HEAD.
-'
-    exit 1
-}
-
 strategy_args= no_summary= no_commit=
 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
 do
diff --git a/git-push.sh b/git-push.sh
index 140c8f8..1c5cf80 100755
--- a/git-push.sh
+++ b/git-push.sh
@@ -1,10 +1,7 @@
 #!/bin/sh
-. git-sh-setup
-
-usage () {
-    die "Usage: git push [--all] [--force] <repository> [<refspec>]"
-}
 
+USAGE='[--all] [--force] <repository> [<refspec>...]'
+. git-sh-setup
 
 # Parse out parameters and then stop at remote, so that we can
 # translate it using .git/branches information
diff --git a/git-request-pull.sh b/git-request-pull.sh
index ae6cd27..2c48bfb 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -4,13 +4,11 @@
 # This file is licensed under the GPL v2, or a later version
 # at the discretion of Linus Torvalds.
 
-usage()
-{
-	echo "$0 <commit> <url> [ <head> ]"
-	echo "  Summarizes the changes since <commit> to the standard output,"
-	echo "  and includes <url> in the message generated."
-	exit 1
-}
+USAGE='<commit> <url> [<head>]'
+LONG_USAGE='Summarizes the changes since <commit> to the standard output,
+and includes <url> in the message generated.'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
 
 revision=$1
 url=$2
diff --git a/git-reset.sh b/git-reset.sh
index 72ef303..eb44ee8 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -1,9 +1,7 @@
 #!/bin/sh
-. git-sh-setup
 
-usage () {
-	die 'Usage: git reset [--mixed | --soft | --hard]  [<commit-ish>]'
-}
+USAGE='[--mixed | --soft | --hard]  [<commit-ish>]'
+. git-sh-setup
 
 tmp=/var/tmp/reset.$$
 trap 'rm -f $tmp-*' 0 1 2 3 15
diff --git a/git-resolve.sh b/git-resolve.sh
index fcc5ad7..9263070 100755
--- a/git-resolve.sh
+++ b/git-resolve.sh
@@ -4,11 +4,9 @@
 #
 # Resolve two trees.
 #
-. git-sh-setup
 
-usage () {
-	die "git-resolve <head> <remote> <merge-message>"
-}
+USAGE='<head> <remote> <merge-message>'
+. git-sh-setup
 
 dropheads() {
 	rm -f -- "$GIT_DIR/MERGE_HEAD" \
diff --git a/git-tag.sh b/git-tag.sh
index 2435a75..6d0c973 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -1,17 +1,9 @@
 #!/bin/sh
 # Copyright (c) 2005 Linus Torvalds
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
-
-usage () {
-    echo >&2 "Usage: git-tag [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
-    exit 1
-}
-
-die () {
-    echo >&2 "$*"
-    exit 1
-}
+USAGE='[-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
 
 annotate=
 signed=
-- 
0.99.9.GIT

[PATCH 9/11] git-prune: Usage string clean-up, use the 'usage' function

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-prune.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

7fb74410bb8975f547d0bae395b74ca783a5cce4
diff --git a/git-prune.sh b/git-prune.sh
index 7e7f0ad..7b61d05 100755
--- a/git-prune.sh
+++ b/git-prune.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+USAGE='[-n] [--] [<head>...]'
 . git-sh-setup
 
 dryrun=
@@ -9,7 +10,7 @@ do
     case "$1" in
     -n) dryrun=-n echo=echo ;;
     --) break ;;
-    -*) echo >&2 "usage: git-prune [ -n ] [ heads... ]"; exit 1 ;;
+    -*) usage ;;
     *)  break ;;
     esac
     shift;
-- 
0.99.9.GIT

[PATCH 11/11] git-repack: Usage string clean-up, emit usage at incorrect invocation

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-repack.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

8b8f12ef2bdb33a0695a82c9f7a4f4eed112ad25
diff --git a/git-repack.sh b/git-repack.sh
index 430ddc5..1fafb6e 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -3,6 +3,7 @@
 # Copyright (c) 2005 Linus Torvalds
 #
 
+USAGE='[-a] [-d] [-l] [-n]'
 . git-sh-setup
 	
 no_update_info= all_into_one= remove_redundant= local=
@@ -13,7 +14,7 @@ do
 	-a)	all_into_one=t ;;
 	-d)	remove_redundant=t ;;
 	-l)	local=t ;;
-	*)	break ;;
+	*)	usage ;;
 	esac
 	shift
 done
-- 
0.99.9.GIT

[PATCH 10/11] git-rebase: Usage string clean-up, emit usage string at incorrect invocation

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-rebase.sh |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

e5739c10c7fb47d091cf774941da6e4b4629f350
diff --git a/git-rebase.sh b/git-rebase.sh
index 638ff0d..8a5f44a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -3,6 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
+USAGE='<upstream> [<head>]'
 . git-sh-setup
 
 # Make sure we do not have .dotest
@@ -19,7 +20,7 @@ you still have something valuable there.
 fi
 
 # The other head is given.  Make sure it is valid.
-other=$(git-rev-parse --verify "$1^0") || exit
+other=$(git-rev-parse --verify "$1^0") || usage
 
 # Make sure we have HEAD that is valid.
 head=$(git-rev-parse --verify "HEAD^0") || exit
@@ -36,7 +37,7 @@ esac
 # If the branch to rebase is given, first switch to it.
 case "$#" in
 2)
-	git-checkout "$2" || exit
+	git-checkout "$2" || usage
 esac
 
 # If the HEAD is a proper descendant of $other, we do not even need
-- 
0.99.9.GIT

[PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-applypatch.sh |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

4aecb38bdf7d1f22bec895d0b3a936ded39bef4d
diff --git a/git-applypatch.sh b/git-applypatch.sh
index a112e1a..214f5c3 100755
--- a/git-applypatch.sh
+++ b/git-applypatch.sh
@@ -10,8 +10,12 @@
 ##	$3 - "info" file with Author, email and subject
 ##	$4 - optional file containing signoff to add
 ##
+
+USAGE='<msg> <patch> <info> [<signoff>]'
 . git-sh-setup
 
+[[ "$#" = "3" || "$#" = "4" ]] || usage
+
 final=.dotest/final-commit
 ##
 ## If this file exists, we ask before applying
-- 
0.99.9.GIT

[PATCH 7/11] git-fetch: Usage string clean-up, emit usage string at unrecognized option

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-fetch.sh |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

64d3f091f8cfa405ee479f49c4890ae452ac0afd
diff --git a/git-fetch.sh b/git-fetch.sh
index 14ea295..767ca61 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 #
+
+USAGE='<fetch-options> <repository> <refspec>...'
 . git-sh-setup
 . git-parse-remote
 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
@@ -34,6 +36,9 @@ do
 	-v|--verbose)
 		verbose=Yes
 		;;
+	-*)
+		usage
+		;;
 	*)
 		break
 		;;
-- 
0.99.9.GIT

[PATCH 6/11] git-cherry: Usage string clean-up, use the 'usage' function

From: <hidden>
Date: 2016-06-15 22:42:14

Signed-off-by: Fredrik Kuivinen <redacted>

---

 git-cherry.sh |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

a3b435a4c9bbde849dbe1aac1431387d673cf754
diff --git a/git-cherry.sh b/git-cherry.sh
index 867522b..5e9bd0c 100755
--- a/git-cherry.sh
+++ b/git-cherry.sh
@@ -3,11 +3,8 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
-. git-sh-setup
-
-usage="usage: $0 "'[-v] <upstream> [<head>]
-
-             __*__*__*__*__> <upstream>
+USAGE='[-v] <upstream> [<head>]'
+LONG_USAGE='             __*__*__*__*__> <upstream>
             /
   fork-point
             \__+__+__+__+__+__+__+__> <head>
@@ -16,8 +13,8 @@ Each commit between the fork-point and <
 compared against the change each commit between the fork-point and
 <upstream> introduces.  If the change seems to be in the upstream,
 it is shown on the standard output with prefix "+".  Otherwise
-it is shown with prefix "-".
-'
+it is shown with prefix "-".'
+. git-sh-setup
 
 case "$1" in -v) verbose=t; shift ;; esac 
 
@@ -35,7 +32,7 @@ case "$#" in
 2) upstream=`git-rev-parse --verify "$1"` &&
    ours=`git-rev-parse --verify "$2"` || exit
    ;;
-*) echo >&2 "$usage"; exit 1 ;;
+*) usage ;;
 esac
 
 # Note that these list commits in reverse order;
-- 
0.99.9.GIT

Re: [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:14

freku045@student.liu.se writes:
 . git-sh-setup
 
+[[ "$#" = "3" || "$#" = "4" ]] || usage
+
I do not see much advantage to use [[...]] construct here.

	http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_04

talks about [[ ... ]] being "some implementations causing
unspecified results".

Re: [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation

From: Timo Hirvonen <hidden>
Date: 2016-06-15 22:42:14

On Tue, 13 Dec 2005 21:20:57 -0800
Junio C Hamano [off-list ref] wrote:
freku045@student.liu.se writes:
quoted
 . git-sh-setup
 
+[[ "$#" = "3" || "$#" = "4" ]] || usage
+
I do not see much advantage to use [[...]] construct here.
[[ ]] is bashishm. Does not work with ash.


test $# -ge 3 && test $# -le 4 || usage

You don't need to quote $# because it is always defined (and always
non-negative integer).  You can't unset or set it.

-- 
http://onion.dynserv.net/~timo/

Re: [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation

From: Fredrik Kuivinen <hidden>
Date: 2016-06-15 22:42:15

On Wed, Dec 14, 2005 at 02:45:42PM +0200, Timo Hirvonen wrote:
On Tue, 13 Dec 2005 21:20:57 -0800
Junio C Hamano [off-list ref] wrote:
quoted
freku045@student.liu.se writes:
quoted
 . git-sh-setup
 
+[[ "$#" = "3" || "$#" = "4" ]] || usage
+
I do not see much advantage to use [[...]] construct here.
[[ ]] is bashishm. Does not work with ash.


test $# -ge 3 && test $# -le 4 || usage

You don't need to quote $# because it is always defined (and always
non-negative integer).  You can't unset or set it.
Thanks. I guess this is what happens when you try to learn sh
programming from the bash manpage. :)

- Fredrik

Re: [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation

From: Marco Costalba <hidden>
Date: 2016-06-15 22:42:15

Fredrik Kuivinen wrote:
On Wed, Dec 14, 2005 at 02:45:42PM +0200, Timo Hirvonen wrote:
quoted
On Tue, 13 Dec 2005 21:20:57 -0800
Junio C Hamano [off-list ref] wrote:

quoted
freku045@student.liu.se writes:

quoted
. git-sh-setup

+[[ "$#" = "3" || "$#" = "4" ]] || usage
+
I do not see much advantage to use [[...]] construct here.
[[ ]] is bashishm. Does not work with ash.


test $# -ge 3 && test $# -le 4 || usage

You don't need to quote $# because it is always defined (and always
non-negative integer).  You can't unset or set it.
This patch seems not working for me:

$ git-applymbox -k 0001-JUST-A-TEST.txt
1 patch(es) to process.
Usage: /home/marco/bin/git-applypatch <msg> <patch> <info> [<signoff>]


where

$ cat 0001-JUST-A-TEST.txt
 From nobody Mon Sep 17 00:00:00 2001
Subject: [PATCH] JUST A TEST
From: Marco Costalba <redacted>
Date: 1134677832 +0100

---

  git-applypatch.sh |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

ee8ea125fd2b0598e26e1556210abb9d0edc459a
diff --git a/git-applypatch.sh b/git-applypatch.sh
index e8ba34a..26b4cba 100755
--- a/git-applypatch.sh
+++ b/git-applypatch.sh
@@ -10,7 +10,7 @@
  ##     $3 - "info" file with Author, email and subject
  ##     $4 - optional file containing signoff to add
  ##
-
+## JUST A TEST
  USAGE='<msg> <patch> <info> [<signoff>]'
  . git-sh-setup

--
0.99.9.GIT


The offending patch is

Author: Junio C Hamano [off-list ref]
Date:   14/12/2005 03:19:12
Parent: git-repack: Usage string clean-up, emit usage at incorrec...

    applypatch: no need to do non-portable [[ ... ]]


    ... when old, proven, case would do.

    Signed-off-by: Junio C Hamano [off-list ref]
--- a/git-applypatch.sh
+++ b/git-applypatch.sh
@@ -14,7 +14,7 @@
  USAGE='<msg> <patch> <info> [<signoff>]'
  . git-sh-setup

-[[ "$#" = "3" || "$#" = "4" ]] || usage
+case "$#" in 3|4) usage ;; esac

  final=.dotest/final-commit
  ##

reverting the patch everything works fine.

Marco
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help