git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: git <git@vger.kernel.org>
Subject: [PATCH] Better option parsing for gitdiff.sh
Date: Tue, 19 Apr 2005 16:19:19 -0400	[thread overview]
Message-ID: <1113941959.3684.9.camel@dv> (raw)

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


                 reply	other threads:[~2005-04-19 20:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1113941959.3684.9.camel@dv \
    --to=proski@gnu.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).