scripts: checkpatch: allow git revision selections as arguments

- The git commands `git rev-parse` and `git rev-list` were added in
  version 2.19.
- `git rev-parse` can parse revision names or any revision selection and
  return the corresponding git object name. This includes being able to
  parse commit ranges, specific hashes, branch names, git tags, etc.
  See 'https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection' for
  more info.
- If `git rev-parse` returns a range of git objects, `git rev-list` can
  convert it into a list of commit ids.

Signed-off-by: Andrew Mustea <andrew.mustea@microsoft.com>
diff --git a/scripts/checkpatch.sh b/scripts/checkpatch.sh
index 75524b8..1a9dc42 100755
--- a/scripts/checkpatch.sh
+++ b/scripts/checkpatch.sh
@@ -24,7 +24,9 @@
 usage() {
   SCR=$(basename "$0")
   echo "Usage: $SCR [--working]                 Check working area"
-  echo "       $SCR <commit>...                 Check specific commit(s)"
+  echo "       $SCR <commit>...                 Check specific commits,
+                                                symbolic names, and/or revision
+                                                selections"
   echo "       $SCR --diff <commit1> <commit2>  Check diff commit1...commit2"
   echo "       $SCR --cached                    Check staging area"
   echo "       $SCR --help                      This help"
@@ -50,7 +52,23 @@
 		;;
 	*)
 		echo "Checking commit(s):"
-		for c in $*; do checkpatch $c; done
-		;;
+    read -r MAJOR MINOR < <(git --version | awk -F '[. ]' '{print $3, $4}')
+    if (( MAJOR < 2 )) || (( MAJOR == 2 && MINOR < 19 )); then
+      for c in "$@"; do checkpatch "$c"; done
+    else
+      for arg in "$@"; do
+        # parse the argument into a git object or list of git objects
+        object="$(git rev-parse "${arg}")" || continue
+        # run checkpatch if the parsed argument represents a single commit hash
+        if git cat-file -e "${object}" 2>/dev/null; then
+          checkpatch "${object}"
+        else
+          # expand the object list and run checkpatch on each commit id
+          commits="$(echo "${object}" | git rev-list --stdin)"
+          for c in ${commits}; do checkpatch "$c"; done
+        fi
+      done
+    fi
+    ;;
 
 esac