Add a script to help review gerrit patch sets
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 1 Nov 2016 17:36:56 +0000 (13:36 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 1 Nov 2016 17:36:56 +0000 (13:36 -0400)
Like git track-review, this grabs a branch for a gerrit change (with git
gerrit-track), extracts it into patches, and runs checkpatch.

It could just as easily call git checkpatch, but breaking it into .patches
helps a little.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
scripts/git/git-gerrit-track-review [new file with mode: 0755]

diff --git a/scripts/git/git-gerrit-track-review b/scripts/git/git-gerrit-track-review
new file mode 100755 (executable)
index 0000000..47b6792
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Barret Rhoden (brho@cs.berkeley.edu)
+# Copyright 2016 Google Inc
+#
+# Tracks a gerrit branch and runs checkpatch on the commits from the
+# merge point of master to the tip of the branch.
+
+PATCHDIR="${PATCHDIR:-../patches}"
+
+usage()
+{
+       echo "$0 <gerrit-number> <local-branch-name>"
+       exit -1
+}
+
+if [ $# -lt 2 ]
+then
+       usage
+fi
+
+if [ ! -f ./scripts/checkpatch.pl ]
+then
+       echo "Run from the root of the Akaros repo"
+       exit -1
+fi
+
+git gerrit-track $1 $2
+
+if [ $? -ne 0 ]
+then
+       exit -1
+fi
+
+FROM=`git merge-base master $2`
+
+if [ $? -ne 0 ]
+then
+       echo "From failed; $FROM"
+       exit -1
+fi
+
+ls $PATCHDIR/*.patch 2>/dev/null
+
+if [ $? -eq 0 ]
+then
+       echo "$PATCHDIR has patches, remove and try again"
+       exit -1
+fi
+
+git format-patch -k -M -N -o $PATCHDIR $FROM..$2
+
+./scripts/checkpatch.pl $PATCHDIR/*