{"thread":{"id":"146","subject":"[PATCH] Better option parsing for gitdiff.sh","startedAt":"2005-04-19T20:19:19Z","lastAt":"2005-04-19T20:19:19Z","messageCount":1,"participants":["Pavel Roskin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"862","messageId":"1113941959.3684.9.camel@dv","threadId":"146","inReplyTo":null,"subject":"[PATCH] Better option parsing for gitdiff.sh","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-04-19T20:19:19Z","receivedAt":"2005-04-19T20:19:19Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello!\n\nThis patch improves option handling for gitdiff.sh.  Now \"-p\" doesn't\nneed to precede \"-r\", although all options still have to be placed\nbefore the file names.  Also, the patch introduces a minimal usage info\nfor the script.\n\nThe patch is against current git-pasky.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\n--- a/gitdiff.sh\n+++ b/gitdiff.sh\n@@ -27,6 +27,13 @@ die () {\n \texit 1\n }\n \n+usage () {\n+\techo \"Usage:\" >&2\n+\techo \"  gitdiff.sh -r rev1:rev2 [FILES...]\" >&2\n+\techo \"  gitdiff.sh -r rev1 -r rev2 [FILES...]\" >&2\n+\texit 1\n+}\n+\n diffqfile () {\n \tdir=$1; shift\n \tfile=$1; shift\n@@ -59,26 +66,44 @@ diffqueue () {\n \treturn $ret\n }\n \n-\n-# FIXME: The commandline parsing is awful.\n-\n-if [ \"$1\" = \"-p\" ]; then\n-\tshift\n-\tparent=1\n-fi\n-\n-if [ \"$1\" = \"-r\" ]; then\n-\tshift\n-\tid1=$(echo \"$1\": | cut -d : -f 1)\n-\t[ \"$id1\" != \"$1\" ] && id2=$(echo \"$1\": | cut -d : -f 2)\n-\tshift\n-fi\n-\n-if [ \"$1\" = \"-r\" ]; then\n-\tshift\n-\tid2=\"$1\"\n-\tshift\n-fi\n+# Parsing the command line\n+id1_set=\n+id2_set=\n+while true; do\n+\tcase $1 in\n+\t-p)\n+\t\tparent=1\n+\t\tshift\n+\t\t;;\n+\t-r)\n+\t\tif test \"$id2_set\"; then\n+\t\t\techo \"Too many revision numbers\" 2>&1\n+\t\t\tusage\n+\t\telif test \"$id1_set\"; then\n+\t\t\tshift\n+\t\t\tid2=\"$1\"\n+\t\t\tid2_set=1\n+\t\t\tshift\n+\t\telse\n+\t\t\tshift\n+\t\t\tid1=$(echo \"$1\": | cut -d : -f 1)\n+\t\t\tid1_set=1\n+\t\t\tif test \"$id1\" != \"$1\"; then\n+\t\t\t\tid2=$(echo \"$1\": | cut -d : -f 2)\n+\t\t\t\tid2_set=1\n+\t\t\tfi\n+\t\t\tshift\n+\t\tfi\n+\t\t;;\n+\t-*)\n+\t\techo \"Unknown option $1\" 2>&1\n+\t\tusage\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+done\n \n if [ \"$parent\" ]; then\n \tid2=\"$id1\"\n\n\n\n-- \nRegards,\nPavel Roskin\n\n"}]}