blob: 12670a242adebd33077bf916f616505870cd09f0 [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):
Mike Frysinger124bb8e2023-09-06 05:48:55 +000022 name = re.sub(r'~.*$', '', git.run('name-rev', '--tags', '--name-only',
23 sha1))
24 if name == 'undefined':
25 name = git.run('name-rev', '--refs', 'remotes/branch-heads/*',
26 '--name-only', sha1) + ' [untagged]'
27 return name
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000028
29
30def GetMergesForCommit(sha1):
Mike Frysinger124bb8e2023-09-06 05:48:55 +000031 return [
32 c.split()[0]
33 for c in git.run('log', '--oneline', '-F', '--all', '--no-abbrev',
34 '--grep', 'cherry picked from commit %s' %
35 sha1).splitlines()
36 ]
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000037
38
Josip Sokcevic1850bf62020-03-18 16:33:58 +000039def main(args):
Mike Frysinger124bb8e2023-09-06 05:48:55 +000040 parser = optparse.OptionParser(usage=sys.modules[__name__].__doc__)
41 _, args = parser.parse_args(args)
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000042
Mike Frysinger124bb8e2023-09-06 05:48:55 +000043 if len(args) == 0:
44 parser.error('Need at least one commit.')
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000045
Mike Frysinger124bb8e2023-09-06 05:48:55 +000046 for arg in args:
47 commit_name = GetNameForCommit(arg)
48 if not commit_name:
49 print('%s not found' % arg)
50 return 1
51 print('commit %s was:' % arg)
52 print(' initially in ' + commit_name)
53 merges = GetMergesForCommit(arg)
54 for merge in merges:
55 print(' merged to ' + GetNameForCommit(merge) + ' (as ' + merge +
56 ')')
57 if not merges:
58 print('No merges found. If this seems wrong, be sure that you did:')
59 print(' git fetch origin && gclient sync --with_branch_heads')
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000060
Mike Frysinger124bb8e2023-09-06 05:48:55 +000061 return 0
scottmg@chromium.orgf4ddadc2015-09-08 21:46:03 +000062
63
64if __name__ == '__main__':
Mike Frysinger124bb8e2023-09-06 05:48:55 +000065 try:
66 sys.exit(main(sys.argv[1:]))
67 except KeyboardInterrupt:
68 sys.stderr.write('interrupted\n')
69 sys.exit(1)