git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Better option parsing for gitdiff.sh
@ 2005-04-19 20:19 Pavel Roskin
  0 siblings, 0 replies; only message in thread
From: Pavel Roskin @ 2005-04-19 20:19 UTC (permalink / raw)
  To: git

Hello!

This patch improves option handling for gitdiff.sh.  Now "-p" doesn't
need to precede "-r", although all options still have to be placed
before the file names.  Also, the patch introduces a minimal usage info
for the script.

The patch is against current git-pasky.

Signed-off-by: Pavel Roskin <proski@gnu.org>

--- a/gitdiff.sh
+++ b/gitdiff.sh
@@ -27,6 +27,13 @@ die () {
 	exit 1
 }
 
+usage () {
+	echo "Usage:" >&2
+	echo "  gitdiff.sh -r rev1:rev2 [FILES...]" >&2
+	echo "  gitdiff.sh -r rev1 -r rev2 [FILES...]" >&2
+	exit 1
+}
+
 diffqfile () {
 	dir=$1; shift
 	file=$1; shift
@@ -59,26 +66,44 @@ diffqueue () {
 	return $ret
 }
 
-
-# FIXME: The commandline parsing is awful.
-
-if [ "$1" = "-p" ]; then
-	shift
-	parent=1
-fi
-
-if [ "$1" = "-r" ]; then
-	shift
-	id1=$(echo "$1": | cut -d : -f 1)
-	[ "$id1" != "$1" ] && id2=$(echo "$1": | cut -d : -f 2)
-	shift
-fi
-
-if [ "$1" = "-r" ]; then
-	shift
-	id2="$1"
-	shift
-fi
+# Parsing the command line
+id1_set=
+id2_set=
+while true; do
+	case $1 in
+	-p)
+		parent=1
+		shift
+		;;
+	-r)
+		if test "$id2_set"; then
+			echo "Too many revision numbers" 2>&1
+			usage
+		elif test "$id1_set"; then
+			shift
+			id2="$1"
+			id2_set=1
+			shift
+		else
+			shift
+			id1=$(echo "$1": | cut -d : -f 1)
+			id1_set=1
+			if test "$id1" != "$1"; then
+				id2=$(echo "$1": | cut -d : -f 2)
+				id2_set=1
+			fi
+			shift
+		fi
+		;;
+	-*)
+		echo "Unknown option $1" 2>&1
+		usage
+		;;
+	*)
+		break
+		;;
+	esac
+done
 
 if [ "$parent" ]; then
 	id2="$id1"



-- 
Regards,
Pavel Roskin


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-04-19 20:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-19 20:19 [PATCH] Better option parsing for gitdiff.sh Pavel Roskin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).