Better flag parsing; build by default
authorRich Salz <rsalz@akamai.com>
Mon, 21 May 2018 12:50:06 +0000 (08:50 -0400)
committerRich Salz <rsalz@akamai.com>
Thu, 21 Jun 2018 14:51:07 +0000 (10:51 -0400)
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/tools/pull/15)

review-tools/ghmerge

index 7f00b7c8a1c111095e6e4f5d82ed8c826105473f..1fb70c81dfd08e936d7ca27d4de5fe1d0b2a4f88 100755 (executable)
@@ -12,36 +12,49 @@ if [ ! -d .git ] ; then
     exit 1
 fi
 
-if [ "$1" = "--tools" ] ; then
-    WHAT=tools ; MERGE=yes ; BUILD=no ; shift
-fi
-if [ "$1" = "--web" ] ; then
-    WHAT=web ; MERGE=yes ; BUILD=no ; shift
-fi
-if [ "$1" == "--trivial" ] ; then
-    TRIVIAL="--trivial" ; shift
-fi
-if [ "$1" == "--merge" -o "$1" == "--squash" ] ; then
-    MERGE=yes ; shift
-fi
-if [ "$1" == "--nomerge" -o "$1" == "--nosquash" ] ; then
-    MERGE=no ; shift
-fi
+# Parse JCL.
+while true ; do
+    case "$1" in
+    --tools)
+        WHAT=tools ; MERGE=yes ; BUILD=no ; shift
+        ;;
+    --web)
+        WHAT=web ; MERGE=yes ; BUILD=no ; shift
+        ;;
+    --trivial)
+        TRIVIAL="--trivial" ; shift
+        ;;
+    --merge | --squash)
+        MERGE=yes ; shift
+        ;;
+    --nomerge | --nosquash)
+        MERGE=no ; shift
+        ;;
+    --nobuild)
+        BUILD=no ; shift
+        ;;
+    --)
+        shift
+        break
+        ;;
+    -*)
+        echo "$0: Unknown flag $1"
+        exit 1
+        ;;
+    *)
+        break
+        ;;
+    esac
+done
 
 if [ $# -lt 2 ] ; then
-    echo Usage: `basename $0` '[--trivial] [--merge] prnum reviewer...'
+    echo "Usage: $0 [flags] prnum reviewer..."
     exit 1
 fi
 PRNUM=$1 ; shift
-case "$PRNUM" in
-    -*)
-        echo Usage: `basename $0` '[--trivial] [--[no]merge] prnum reviewer...'
-        exit 1
-        ;;
-esac
+TEAM=$*
 
 curl -s https://api.github.com/repos/openssl/$WHAT/pulls/$PRNUM >/tmp/gh$$
-TEAM=$*
 set -- `python -c '
 from __future__ import print_function
 import json, sys;
@@ -69,13 +82,13 @@ function cleanup {
 }
 trap 'cleanup' EXIT
 
-
 git pull --rebase https://github.com/$WHO/$WHAT.git $BRANCH
 git rebase $REL
+
 echo Diff against $REL
 git diff $REL
 
-echo -n Press return to merge to $REL and build: ; read foo
+echo -n Press return to merge to $REL: ; read foo
 addrev $TRIVIAL --prnum=$PRNUM $TEAM ${REL}..
 git checkout $REL
 if [ "$MERGE" == "yes" ] ; then
@@ -86,8 +99,10 @@ else
     git rebase $WORK
 fi
 
-# echo Rebuilding
-# opensslbuild |& tail -3
+if [ "$BUILD" == "yes" ] ; then
+    echo Rebuilding
+    ( opensslbuild 2>&1 ) | tail -3
+fi
 
 while true ; do
     echo -n "Enter YES to push or NO to abort: "