Adding branch-compare command and renaming clean-branches.py to branch-clean

Change-Id: I8fdb27749893fefbe27bba02437b36e7860701b4
diff --git a/tools/dev/bin/clean-branches.py b/tools/dev/bin/branch-clean
similarity index 100%
rename from tools/dev/bin/clean-branches.py
rename to tools/dev/bin/branch-clean
diff --git a/tools/dev/bin/branch-compare b/tools/dev/bin/branch-compare
new file mode 100755
index 0000000..2ea535d
--- /dev/null
+++ b/tools/dev/bin/branch-compare
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+import os
+import re
+import sys
+
+from git import Git
+
+g = Git(os.getcwd())
+
+commitMsgs = {}
+
+def getCommits(srcRef, dstRef):
+  commits = {}
+  
+  commit = ''
+  changeId = ''
+  commitHash = ''
+  for line in g.log('--format=fuller', '%s..%s' % (srcRef, dstRef)).split('\n'):
+    if len(commit) > 0 and line.find('commit') == 0:
+      commits[changeId] = commitHash
+      commitMsgs[commitHash] = commit
+      commit = ''
+      size = 0
+      match = re.search(r'commit ([0-9a-f]+)', line)
+      if match:
+        commitHash = match.group(1)
+      else:
+        raise Exception('Bad commit hash in line:\n%s' % line)
+    elif line.find('Change-Id:') >= 0:
+      match = re.search(r'Change-Id: (I[0-9a-f]+)', line)
+      if match:
+        changeId = match.group(1)
+      else:
+        raise Exception('Bad Change-Id in line:\n%s' % line)
+    commit += line + '\n'
+  
+  return commits
+
+
+if __name__ == '__main__':
+  try:
+    sourceRef, targetRef = sys.argv[1:3]
+  except ValueError:
+    print 'branch-compare <source ref> <target ref>'
+
+  targetCommits = getCommits(sourceRef, targetRef)
+  sourceCommits = getCommits(targetRef, sourceRef)
+  
+  missingCommitsFromTarget = set(sourceCommits.keys()) - set(targetCommits.keys())
+  
+  for id in missingCommitsFromTarget:
+    hash = sourceCommits[id]
+    print 'git cherry-pick', hash
+    print commitMsgs[hash]