blob: 64de921bd3c8ab0713711685c0be871d0916b6e7 [file] [log] [blame]
Josip Sokcevic4de5dea2022-03-23 21:15:14 +00001#!/usr/bin/env python3
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
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
Josip Sokcevic1850bf62020-03-18 16:33:58 +000036def main(args):
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000037 parser = optparse.OptionParser(usage=sys.modules[__name__].__doc__)
Josip Sokcevic1850bf62020-03-18 16:33:58 +000038 _, args = parser.parse_args(args)
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000039
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:
Raul Tambre80ee78e2019-05-06 22:41:05 +000046 print('%s not found' % arg)
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000047 return 1
Raul Tambre80ee78e2019-05-06 22:41:05 +000048 print('commit %s was:' % arg)
49 print(' initially in ' + commit_name)
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000050 merges = GetMergesForCommit(arg)
51 for merge in merges:
Raul Tambre80ee78e2019-05-06 22:41:05 +000052 print(' merged to ' + GetNameForCommit(merge) + ' (as ' + merge + ')')
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000053 if not merges:
Raul Tambre80ee78e2019-05-06 22:41:05 +000054 print('No merges found. If this seems wrong, be sure that you did:')
55 print(' git fetch origin && gclient sync --with_branch_heads')
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000056
57 return 0
58
59
60if __name__ == '__main__':
61 try:
Josip Sokcevic1850bf62020-03-18 16:33:58 +000062 sys.exit(main(sys.argv[1:]))
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000063 except KeyboardInterrupt:
64 sys.stderr.write('interrupted\n')
65 sys.exit(1)