blob: ef65c0e6d7a5380aa457681d245937a293a56adf [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):
scottmg@chromium.orgb62f6752015-09-09 23:15:36 +000022 name = re.sub(r'~.*$', '', git.run('name-rev', '--tags', '--name-only', sha1))
23 if name == 'undefined':
24 name = git.run(
25 'name-rev', '--refs', 'remotes/branch-heads/*', '--name-only',
26 sha1) + ' [untagged]'
27 return name
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000028
29
30def GetMergesForCommit(sha1):
31 return [c.split()[0] for c in
32 git.run('log', '--oneline', '-F', '--all', '--no-abbrev', '--grep',
33 'cherry picked from commit %s' % sha1).splitlines()]
34
35
36def main():
37 parser = optparse.OptionParser(usage=sys.modules[__name__].__doc__)
38 _, args = parser.parse_args()
39
40 if len(args) == 0:
41 parser.error('Need at least one commit.')
42
43 for arg in args:
44 commit_name = GetNameForCommit(arg)
45 if not commit_name:
46 print '%s not found' % arg
47 return 1
48 print 'commit %s was:' % arg
49 print ' initially in ' + commit_name
50 merges = GetMergesForCommit(arg)
51 for merge in merges:
52 print ' merged to ' + GetNameForCommit(merge) + ' (as ' + merge + ')'
53 if not merges:
54 print 'No merges found. If this seems wrong, be sure that you did:'
55 print ' git fetch origin && gclient sync --with_branch_heads'
56
57 return 0
58
59
60if __name__ == '__main__':
61 try:
62 sys.exit(main())
63 except KeyboardInterrupt:
64 sys.stderr.write('interrupted\n')
65 sys.exit(1)