Adding branch-compare command and renaming clean-branches.py to branch-clean
Change-Id: I8fdb27749893fefbe27bba02437b36e7860701b4
Showing
2 changed files
with
55 additions
and
0 deletions
tools/dev/bin/branch-compare
0 → 100755
| 1 | +#!/usr/bin/env python | ||
| 2 | + | ||
| 3 | +import os | ||
| 4 | +import re | ||
| 5 | +import sys | ||
| 6 | + | ||
| 7 | +from git import Git | ||
| 8 | + | ||
| 9 | +g = Git(os.getcwd()) | ||
| 10 | + | ||
| 11 | +commitMsgs = {} | ||
| 12 | + | ||
| 13 | +def getCommits(srcRef, dstRef): | ||
| 14 | + commits = {} | ||
| 15 | + | ||
| 16 | + commit = '' | ||
| 17 | + changeId = '' | ||
| 18 | + commitHash = '' | ||
| 19 | + for line in g.log('--format=fuller', '%s..%s' % (srcRef, dstRef)).split('\n'): | ||
| 20 | + if len(commit) > 0 and line.find('commit') == 0: | ||
| 21 | + commits[changeId] = commitHash | ||
| 22 | + commitMsgs[commitHash] = commit | ||
| 23 | + commit = '' | ||
| 24 | + size = 0 | ||
| 25 | + match = re.search(r'commit ([0-9a-f]+)', line) | ||
| 26 | + if match: | ||
| 27 | + commitHash = match.group(1) | ||
| 28 | + else: | ||
| 29 | + raise Exception('Bad commit hash in line:\n%s' % line) | ||
| 30 | + elif line.find('Change-Id:') >= 0: | ||
| 31 | + match = re.search(r'Change-Id: (I[0-9a-f]+)', line) | ||
| 32 | + if match: | ||
| 33 | + changeId = match.group(1) | ||
| 34 | + else: | ||
| 35 | + raise Exception('Bad Change-Id in line:\n%s' % line) | ||
| 36 | + commit += line + '\n' | ||
| 37 | + | ||
| 38 | + return commits | ||
| 39 | + | ||
| 40 | + | ||
| 41 | +if __name__ == '__main__': | ||
| 42 | + try: | ||
| 43 | + sourceRef, targetRef = sys.argv[1:3] | ||
| 44 | + except ValueError: | ||
| 45 | + print 'branch-compare <source ref> <target ref>' | ||
| 46 | + | ||
| 47 | + targetCommits = getCommits(sourceRef, targetRef) | ||
| 48 | + sourceCommits = getCommits(targetRef, sourceRef) | ||
| 49 | + | ||
| 50 | + missingCommitsFromTarget = set(sourceCommits.keys()) - set(targetCommits.keys()) | ||
| 51 | + | ||
| 52 | + for id in missingCommitsFromTarget: | ||
| 53 | + hash = sourceCommits[id] | ||
| 54 | + print 'git cherry-pick', hash | ||
| 55 | + print commitMsgs[hash] |
-
Please register or login to post a comment