Edward Lemur | d6186f9 | 2019-08-12 17:56:58 +0000 | [diff] [blame] | 1 | #!/usr/bin/env vpython |
scottmg@chromium.org | f4ddadc | 2015-09-08 21:46:03 +0000 | [diff] [blame] | 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 | |
| 7 | Given a commit, finds the release where it first appeared (e.g. 47.0.2500.0) as |
| 8 | well as attempting to determine the branches to which it was merged. |
| 9 | |
| 10 | Note that it uses the "cherry picked from" annotation to find merges, so it will |
| 11 | only work on merges that followed the "use cherry-pick -x" instructions. |
| 12 | """ |
| 13 | |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 14 | from __future__ import print_function |
| 15 | |
scottmg@chromium.org | f4ddadc | 2015-09-08 21:46:03 +0000 | [diff] [blame] | 16 | import optparse |
| 17 | import re |
| 18 | import sys |
| 19 | |
| 20 | import git_common as git |
| 21 | |
| 22 | |
| 23 | def GetNameForCommit(sha1): |
scottmg@chromium.org | b62f675 | 2015-09-09 23:15:36 +0000 | [diff] [blame] | 24 | 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.org | f4ddadc | 2015-09-08 21:46:03 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | def 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 | |
| 38 | def 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 Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 48 | print('%s not found' % arg) |
scottmg@chromium.org | f4ddadc | 2015-09-08 21:46:03 +0000 | [diff] [blame] | 49 | return 1 |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 50 | print('commit %s was:' % arg) |
| 51 | print(' initially in ' + commit_name) |
scottmg@chromium.org | f4ddadc | 2015-09-08 21:46:03 +0000 | [diff] [blame] | 52 | merges = GetMergesForCommit(arg) |
| 53 | for merge in merges: |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 54 | print(' merged to ' + GetNameForCommit(merge) + ' (as ' + merge + ')') |
scottmg@chromium.org | f4ddadc | 2015-09-08 21:46:03 +0000 | [diff] [blame] | 55 | if not merges: |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 56 | 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.org | f4ddadc | 2015-09-08 21:46:03 +0000 | [diff] [blame] | 58 | |
| 59 | return 0 |
| 60 | |
| 61 | |
| 62 | if __name__ == '__main__': |
| 63 | try: |
| 64 | sys.exit(main()) |
| 65 | except KeyboardInterrupt: |
| 66 | sys.stderr.write('interrupted\n') |
| 67 | sys.exit(1) |