devel/review: make the range argument optional
authorGuido Trotter <ultrotter@google.com>
Mon, 17 May 2010 12:30:46 +0000 (13:30 +0100)
committerGuido Trotter <ultrotter@google.com>
Thu, 20 May 2010 14:50:08 +0000 (15:50 +0100)
Rather than calling devel/review with from..to target we can just use
target, and assume target..HEAD as the range. This makes it a lot
easier, as now you just have to say something like "devel/review
devel-2.1" if you're already on the branch you want to commit, and want
to commit it to devel-2.1.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

devel/review

index 70cdf81..97433e4 100755 (executable)
@@ -196,14 +196,31 @@ copy_commit() {
   GIT_EDITOR="$me --commit-editor \"\$@\"" git commit -c "$rev" -s
 }
 
-main() {
-  local range="$1" target_branch="$2"
+usage() {
+  echo "Usage: $me_plain [from..to] <target-branch>" >&2
+  echo "  If not passed from..to defaults to target-branch..HEAD" >&2
+  exit 1
+}
 
-  if [[ -z "$target_branch" || "$range" != *..* ]]
-  then
-    echo "Usage: $me_plain <from..to> <target-branch>" >&2
-    exit 1
-  fi
+main() {
+  local range target_branch
+
+  case "$#" in
+  1)
+    target_branch="$1"
+    range="$target_branch..$(git rev-parse HEAD)"
+  ;;
+  2)
+    range="$1"
+    target_branch="$2"
+    if [[ "$range" != *..* ]]; then
+      usage
+    fi
+  ;;
+  *)
+    usage
+  ;;
+  esac
 
   git checkout "$target_branch"
   local old_head=$(git rev-parse HEAD)