blob: cab723dd35b0ab83e198abc6c47d4f348925df02 [file] [log] [blame]
Edward Lesmes98eda3f2019-08-12 21:09:53 +00001#!/usr/bin/env python
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +00002# 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
Raul Tambre80ee78e2019-05-06 22:41:05 +000014from __future__ import print_function
15
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000016import optparse
17import re
18import sys
19
20import git_common as git
21
22
23def GetNameForCommit(sha1):
scottmg@chromium.orgb62f6752015-09-09 23:15:36 +000024 name = re.sub(r'~.*$', '', git.run('name-rev', '--tags', '--name-only', sha1))
25 if name == 'undefined':
26 name = git.run(
27 'name-rev', '--refs', 'remotes/branch-heads/*', '--name-only',
28 sha1) + ' [untagged]'
29 return name
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000030
31
32def GetMergesForCommit(sha1):
33 return [c.split()[0] for c in
34 git.run('log', '--oneline', '-F', '--all', '--no-abbrev', '--grep',
35 'cherry picked from commit %s' % sha1).splitlines()]
36
37
38def main():
39 parser = optparse.OptionParser(usage=sys.modules[__name__].__doc__)
40 _, args = parser.parse_args()
41
42 if len(args) == 0:
43 parser.error('Need at least one commit.')
44
45 for arg in args:
46 commit_name = GetNameForCommit(arg)
47 if not commit_name:
Raul Tambre80ee78e2019-05-06 22:41:05 +000048 print('%s not found' % arg)
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000049 return 1
Raul Tambre80ee78e2019-05-06 22:41:05 +000050 print('commit %s was:' % arg)
51 print(' initially in ' + commit_name)
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000052 merges = GetMergesForCommit(arg)
53 for merge in merges:
Raul Tambre80ee78e2019-05-06 22:41:05 +000054 print(' merged to ' + GetNameForCommit(merge) + ' (as ' + merge + ')')
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000055 if not merges:
Raul Tambre80ee78e2019-05-06 22:41:05 +000056 print('No merges found. If this seems wrong, be sure that you did:')
57 print(' git fetch origin && gclient sync --with_branch_heads')
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000058
59 return 0
60
61
62if __name__ == '__main__':
63 try:
64 sys.exit(main())
65 except KeyboardInterrupt:
66 sys.stderr.write('interrupted\n')
67 sys.exit(1)