#!/bin/sh
-. git-sh-setup-script || die "Not a git archive"
+#
+# Copyright (c) 2005 Linus Torvalds
+# Copyright (c) 2005 Junio C Hamano
-rev=($(git-rev-parse --revs-only "$@"))
-flags=($(git-rev-parse --no-revs --flags "$@"))
-files=($(git-rev-parse --no-revs --no-flags "$@"))
-case "${#rev[*]}" in
-0)
- git-diff-files -M -p "$@";;
-1)
- git-diff-cache -M -p "$@";;
-2)
- begin=$(echo "${rev[1]}" | tr -d '^')
- end="${rev[0]}"
- git-diff-tree -M -p $flags $begin $end $files;;
+rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit
+flags=$(git-rev-parse --no-revs --flags --sq "$@")
+files=$(git-rev-parse --no-revs --no-flags --sq "$@")
+
+: ${flags:="'-M' '-p'"}
+
+case "$rev" in
+?*' '?*' '?*)
+ die "I don't understand"
+ ;;
+?*' '^?*)
+ begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') &&
+ end=$(expr "$rev" : '.\([0-9a-f]*\). .*') || exit
+ cmd="git-diff-tree $flags $begin $end $files"
+ ;;
+?*' '?*)
+ cmd="git-diff-tree $flags $rev $files"
+ ;;
+?*' ')
+ cmd="git-diff-cache $flags $rev $files"
+ ;;
+'')
+ cmd="git-diff-files $flags $files"
+ ;;
*)
- echo "I don't understand"
- exit 1;;
+ die "I don't understand $*"
+ ;;
esac
+
+eval "$cmd"