blob: 4bb27c54d814e0b2bb9f1d9938ca58c12367bf9d [file] [log] [blame]
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +00001#!/usr/bin/env python
2# Copyright 2015 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Usage: %prog <commit>*
6
7Given a commit, finds the release where it first appeared (e.g. 47.0.2500.0) as
8well as attempting to determine the branches to which it was merged.
9
10Note that it uses the "cherry picked from" annotation to find merges, so it will
11only work on merges that followed the "use cherry-pick -x" instructions.
12"""
13
14import optparse
15import re
16import sys
17
18import git_common as git
19
20
21def GetNameForCommit(sha1):
22 return re.sub(r'~.*$', '', git.run('name-rev', '--tags', '--name-only', sha1))
23
24
25def GetMergesForCommit(sha1):
26 return [c.split()[0] for c in
27 git.run('log', '--oneline', '-F', '--all', '--no-abbrev', '--grep',
28 'cherry picked from commit %s' % sha1).splitlines()]
29
30
31def main():
32 parser = optparse.OptionParser(usage=sys.modules[__name__].__doc__)
33 _, args = parser.parse_args()
34
35 if len(args) == 0:
36 parser.error('Need at least one commit.')
37
38 for arg in args:
39 commit_name = GetNameForCommit(arg)
40 if not commit_name:
41 print '%s not found' % arg
42 return 1
43 print 'commit %s was:' % arg
44 print ' initially in ' + commit_name
45 merges = GetMergesForCommit(arg)
46 for merge in merges:
47 print ' merged to ' + GetNameForCommit(merge) + ' (as ' + merge + ')'
48 if not merges:
49 print 'No merges found. If this seems wrong, be sure that you did:'
50 print ' git fetch origin && gclient sync --with_branch_heads'
51
52 return 0
53
54
55if __name__ == '__main__':
56 try:
57 sys.exit(main())
58 except KeyboardInterrupt:
59 sys.stderr.write('interrupted\n')
60 sys.exit(1)