aboutsummaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-08-15 15:37:37 -0700
committerJunio C Hamano <junkio@cox.net>2005-08-15 15:37:37 -0700
commitb0c6f8d767387d39058648b4e3a04518350f789c (patch)
tree663fac10d76edde6f869b02a155e2203efdab586 /git
parent2ad77e67c7c95982ebc9b99ee6a2d007feada62e (diff)
downloadgit-b0c6f8d767387d39058648b4e3a04518350f789c.tar.gz
git-b0c6f8d767387d39058648b4e3a04518350f789c.tar.xz
[PATCH] clean up git script
Makes git work with a pure POSIX shell (tested with bash --posix and ash). Right now git causes ash to choke on the redundant shift on line two. Reduces the number of system calls git makes just to do a usage statement from 22610 to 1122, and the runtime for same from 349ms to 29ms on my x86 Linux box. Presents a standard usage statement, and pretty prints the available commands in a form that does not scroll off small terminals. [jc: while shifting when $# was zero was a bug, the original patch failed to shift when it needs to, which I fixed up.] Signed-off-by: Amos Waterland <apw@rossby.metr.ou.edu> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git')
-rwxr-xr-xgit33
1 files changed, 18 insertions, 15 deletions
diff --git a/git b/git
index 9f511956a..0d8b382aa 100755
--- a/git
+++ b/git
@@ -1,19 +1,22 @@
#!/bin/sh
-cmd="$1"
-shift
-if which git-$cmd-script >& /dev/null
-then
- exec git-$cmd-script "$@"
-fi
-if which git-$cmd >& /dev/null
-then
- exec git-$cmd "$@"
-fi
+cmd=
+path=$(dirname $0)
+case "$#" in
+0) ;;
+*) cmd="$1"
+ shift
+ test -x $path/git-$cmd-script && exec $path/git-$cmd-script "$@"
+ test -x $path/git-$cmd && exec $path/git-$cmd "$@" ;;
+esac
-alternatives=($(echo $PATH | tr ':' '\n' | while read i; do ls $i/git-*-script 2> /dev/null; done))
+echo "Usage: git COMMAND [OPTIONS] [TARGET]"
+if [ -n "$cmd" ]; then
+ echo " git command '$cmd' not found: commands are:"
+else
+ echo " git commands are:"
+fi
-echo Git command "'$cmd'" not found. Try one of
-for i in "${alternatives[@]}"; do
- echo $i | sed 's:^.*/git-: :' | sed 's:-script$::'
-done | sort | uniq
+alternatives=$(cd $path &&
+ ls git-*-script | sed -e 's/git-//' -e 's/-script//')
+echo $alternatives | fmt | sed 's/^/ /'