@matheusbsbs / matheus-bagliano / commits / d025524d9d
Fork 0

Usage message clean-up, take #2

There were some problems with the usage message clean-up patch series. I hadn't realised that subdirectory aware scripts can't source git-sh-setup. I propose that we change this and let the scripts which are subdirectory aware set a variable, SUBDIRECTORY_OK, before they source git-sh-setup. The scripts will also set USAGE and possibly LONG_USAGE before they source git-sh-setup. If LONG_USAGE isn't set it defaults to USAGE. If we go this way it's easy to catch --help in git-sh-setup, print the (long) usage message to stdout and exit cleanly. git-sh-setup can define a 'usage' shell function which can be called by the scripts to print the short usage string to stderr and exit non-cleanly. It will also be easy to change $0 to basename $0 or something else, if would like to do that sometime in the future. What follows is a patch to convert a couple of the commands to this style. If it's ok with everyone to do it this way I will convert the rest of the scripts too. [jc: thrown in to proposed updates queue for comments.] Signed-off-by: Junio C Hamano <junkio@cox.net>

Fredrik Kuivinen committed Dec 11, 2005 at 10:55 UTC d025524d9d85b057c3caae68a8398eaf7ba3be1a
4 files changed +56 -34
git-bisect.sh
+11 -13
@@ -1,4 +1,15 @@
1 #!/bin/sh
2 +
3 +USAGE='[start|bad|good|next|reset|visualize]'
4 +LONG_USAGE='git bisect start [<pathspec>] reset bisect state and start bisection.
5 +git bisect bad [<rev>] mark <rev> a known-bad revision.
6 +git bisect good [<rev>...] mark <rev>... known-good revisions.
7 +git bisect next find next bisection to test and check it out.
8 +git bisect reset [<branch>] finish bisection search and go back to branch.
9 +git bisect visualize show bisect status in gitk.
10 +git bisect replay <logfile> replay bisection log
11 +git bisect log show bisect log.'
12 +
13 . git-sh-setup
14
15 sq() {
@@ -11,19 +22,6 @@ sq() {
22 ' "$@"
23 }
24
14 -usage() {
15 - echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize]
16 -git bisect start [<pathspec>] reset bisect state and start bisection.
17 -git bisect bad [<rev>] mark <rev> a known-bad revision.
18 -git bisect good [<rev>...] mark <rev>... known-good revisions.
19 -git bisect next find next bisection to test and check it out.
20 -git bisect reset [<branch>] finish bisection search and go back to branch.
21 -git bisect visualize show bisect status in gitk.
22 -git bisect replay <logfile> replay bisection log
23 -git bisect log show bisect log.'
24 - exit 1
25 -}
26 -
25 bisect_autostart() {
26 test -d "$GIT_DIR/refs/bisect" || {
27 echo >&2 'You need to start by "git bisect start"'
git-branch.sh
+6 -15
@@ -1,21 +1,12 @@
1 #!/bin/sh
2
3 -GIT_DIR=`git-rev-parse --git-dir` || exit $?
4 -
5 -die () {
6 - echo >&2 "$*"
7 - exit 1
8 -}
9 -
10 -usage () {
11 - echo >&2 "usage: $(basename $0)"' [-d <branch>] | [[-f] <branch> [start-point]]
12 -
13 -If no arguments, show available branches and mark current branch with a star.
3 +USAGE='[-d <branch>] | [[-f] <branch> [start-point]]'
4 +LONG_USAGE='If no arguments, show available branches and mark current branch with a star.
5 If one argument, create a new branch <branchname> based off of current HEAD.
15 -If two arguments, create a new branch <branchname> based off of <start-point>.
16 -'
17 - exit 1
18 -}
6 +If two arguments, create a new branch <branchname> based off of <start-point>.'
7 +
8 +SUBDIRECTORY_OK='Yes'
9 +. git-sh-setup
10
11 headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
12
git-sh-setup.sh
+29 -5
@@ -11,13 +11,37 @@
11 # exporting it.
12 unset CDPATH
13
14 -: ${GIT_DIR=.git}
15 -: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
16 -
14 die() {
15 echo >&2 "$@"
16 exit 1
17 }
18
22 -# Make sure we are in a valid repository of a vintage we understand.
23 -GIT_DIR="$GIT_DIR" git-var GIT_AUTHOR_IDENT >/dev/null || exit
19 +usage() {
20 + die "Usage: $0 $USAGE"
21 +}
22 +
23 +if [ -z "$LONG_USAGE" ]
24 +then
25 + LONG_USAGE="Usage: $0 $USAGE"
26 +else
27 + LONG_USAGE="Usage: $0 $USAGE
28 +
29 +$LONG_USAGE"
30 +fi
31 +
32 +case "$1" in
33 + --h|--he|--hel|--help)
34 + echo "$LONG_USAGE"
35 + exit
36 +esac
37 +
38 +if [ -z "$SUBDIRECTORY_OK" ]
39 +then
40 + : ${GIT_DIR=.git}
41 + : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
42 +
43 + # Make sure we are in a valid repository of a vintage we understand.
44 + GIT_DIR="$GIT_DIR" git-var GIT_AUTHOR_IDENT >/dev/null || exit
45 +else
46 + GIT_DIR=$(git-rev-parse --git-dir) || exit
47 +fi
git-status.sh
+10 -1
@@ -2,7 +2,16 @@
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
5 -GIT_DIR=$(git-rev-parse --git-dir) || exit
5 +
6 +USAGE=''
7 +SUBDIRECTORY_OK='Yes'
8 +
9 +. git-sh-setup
10 +
11 +if [ "$#" != "0" ]
12 +then
13 + usage
14 +fi
15
16 report () {
17 header="#