Usage string clean-up
cover Usage string clean-up
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 1/11 Trivial usage string clean-up
---
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
git-add.sh +3 -10
@@ -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 \
git-applymbox.sh +1 -5
@@ -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
git-checkout.sh +2 -4
@@ -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=
git-clone.sh +1 -1
@@ -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 }
git-commit.sh +1 -4
@@ -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
git-format-patch.sh +8 -17
@@ -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='
git-grep.sh +5 -2
@@ -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"
git-merge.sh +2 -4
@@ -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=
git-pull.sh +2 -11
@@ -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
git-push.sh +2 -5
@@ -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
git-request-pull.sh +5 -7
@@ -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
git-reset.sh +2 -4
@@ -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
git-resolve.sh +2 -4
@@ -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" \
git-tag.sh +3 -11
@@ -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=
Signature · 1 line
0.99.9.GIT
PATCH 2/11 git-verify-tag: Usage string clean-up, emit usage string at incorrect invocation
In reply to [email protected]---
git-verify-tag.sh | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
e1bab3098c4926a09cb74dc767d03fd0f3bf8343
git-verify-tag.sh +8 -6
@@ -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."
Signature · 1 line
0.99.9.GIT
PATCH 3/11 git-revert: Usage string clean-up
In reply to [email protected]---
git-revert.sh | 19 +++++-------------- 1 files changed, 5 insertions(+), 14 deletions(-)
16ecbff0d2e6cf51ff92f081ad66b5bcc3883e31
git-revert.sh +5 -14
@@ -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
Signature · 1 line
0.99.9.GIT
PATCH 4/11 git-am: Usage string clean-up
In reply to [email protected]---
git-am.sh | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)
243b906a6786cd7401285cacaf9ade994ff83db8
git-am.sh +3 -7
@@ -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"
Signature · 1 line
0.99.9.GIT
PATCH 5/11 git-applypatch: Usage string clean-up, emit usage string at incorrect invocation
In reply to [email protected]---
git-applypatch.sh | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
4aecb38bdf7d1f22bec895d0b3a936ded39bef4d
git-applypatch.sh +4 -0
@@ -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
Signature · 1 line
0.99.9.GIT
Re: [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation
Quoted 4 lines · [email protected] 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
Quoted 8 lines · On Tue, 13 Dec 2005 21:20:57 -0800 Junio C Hamano <[email protected]> wrote:
Quoted 4 lines · [email protected] writes:
. 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.
Signature · 1 line
http://onion.dynserv.net/~timo/
Re: [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation
Quoted 12 lines · Timo Hirvonen
Quoted 8 lines · On Tue, 13 Dec 2005 21:20:57 -0800 Junio C Hamano <[email protected]> wrote:
Quoted 4 lines · [email protected] writes:
. git-sh-setup
+[[ "$#" = "3" || "$#" = "4" ]] || usage
+I do not see much advantage to use [[...]] construct here.
Quoted 7 lines
[[ ]] 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
Quoted 16 lines · Fredrik Kuivinen
Quoted 14 lines · Timo Hirvonen
Quoted 9 lines · On Tue, 13 Dec 2005 21:20:57 -0800 Junio C Hamano <[email protected]> wrote:
Quoted 4 lines · [email protected] writes:
. git-sh-setup
+[[ "$#" = "3" || "$#" = "4" ]] || usage
+I do not see much advantage to use [[...]] construct here.
Quoted 9 lines
Quoted 7 lines
[[ ]] 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 <[email protected]> Date: 1134677832 +0100
---
git-applypatch.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
ee8ea125fd2b0598e26e1556210abb9d0edc459a
git-applypatch.sh +1 -1
@@ -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 <[email protected]> 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.
git-applypatch.sh +1 -1
@@ -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
Re: [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation
Quoted 4 lines · Marco Costalba
This patch seems not working for me:
-[[ "$#" = "3" || "$#" = "4" ]] || usage
+case "$#" in 3|4) usage ;; esac
I am an idiot. Thanks. That should have read "3|4) ;; *) usage", obviously.
PATCH 6/11 git-cherry: Usage string clean-up, use the 'usage' function
In reply to [email protected]---
git-cherry.sh | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-)
a3b435a4c9bbde849dbe1aac1431387d673cf754
git-cherry.sh +5 -8
@@ -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;
Signature · 1 line
0.99.9.GIT
PATCH 7/11 git-fetch: Usage string clean-up, emit usage string at unrecognized option
In reply to [email protected]---
git-fetch.sh | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
64d3f091f8cfa405ee479f49c4890ae452ac0afd
git-fetch.sh +5 -0
@@ -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 ;;
Signature · 1 line
0.99.9.GIT
PATCH 8/11 git-lost-found: Usage string clean-up, emit usage string at incorrect invocation
In reply to [email protected]---
git-lost-found.sh | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
240de5191779f0637fb339a80a76770ee35f5a68
git-lost-found.sh +9 -1
@@ -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
Signature · 1 line
0.99.9.GIT
PATCH 9/11 git-prune: Usage string clean-up, use the 'usage' function
In reply to [email protected]---
git-prune.sh | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
7fb74410bb8975f547d0bae395b74ca783a5cce4
git-prune.sh +2 -1
@@ -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;
Signature · 1 line
0.99.9.GIT
PATCH 10/11 git-rebase: Usage string clean-up, emit usage string at incorrect invocation
In reply to [email protected]---
git-rebase.sh | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
e5739c10c7fb47d091cf774941da6e4b4629f350
git-rebase.sh +3 -2
@@ -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
Signature · 1 line
0.99.9.GIT
PATCH 11/11 git-repack: Usage string clean-up, emit usage at incorrect invocation
In reply to [email protected]---
git-repack.sh | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
8b8f12ef2bdb33a0695a82c9f7a4f4eed112ad25
git-repack.sh +2 -1
@@ -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
Signature · 1 line
0.99.9.GIT