Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 3 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """Git bisector to bisect a range of git commits. |
| 7 | |
| 8 | Example: |
| 9 | $ ./bisect_git.py init --old rev1 --new rev2 --git_repo /path/to/git/repo |
| 10 | $ ./bisect_git.py config switch ./switch_git.py |
| 11 | $ ./bisect_git.py config eval ./eval-manually.sh |
| 12 | $ ./bisect_git.py run |
| 13 | """ |
| 14 | |
| 15 | from __future__ import print_function |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame^] | 16 | import logging |
| 17 | import subprocess |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 18 | |
| 19 | from bisect_kit import cli |
| 20 | from bisect_kit import core |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 21 | from bisect_kit import errors |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 22 | from bisect_kit import git_util |
| 23 | |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame^] | 24 | logger = logging.getLogger(__name__) |
| 25 | |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 26 | |
| 27 | class GitDomain(core.BisectDomain): |
| 28 | """BisectDomain for git revisions.""" |
| 29 | revtype = staticmethod(git_util.argtype_git_rev) |
Kuang-che Wu | b237626 | 2017-11-20 18:05:24 +0800 | [diff] [blame] | 30 | help = globals()['__doc__'] |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 31 | |
| 32 | @staticmethod |
| 33 | def add_init_arguments(parser): |
| 34 | parser.add_argument( |
| 35 | '--git_repo', |
| 36 | required=True, |
| 37 | type=cli.argtype_dir_path, |
| 38 | help='Git repository path') |
| 39 | |
| 40 | @staticmethod |
| 41 | def init(opts): |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 42 | if not git_util.is_containing_commit(opts.git_repo, opts.old): |
| 43 | raise errors.ArgumentError( |
| 44 | '--old', '%s is not in git_repo=%r' % (opts.old, opts.git_repo)) |
| 45 | if not git_util.is_containing_commit(opts.git_repo, opts.new): |
| 46 | raise errors.ArgumentError( |
| 47 | '--new', '%s is not in git_repo=%r' % (opts.new, opts.git_repo)) |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 48 | |
| 49 | config = dict(git_repo=opts.git_repo) |
| 50 | revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new) |
| 51 | return config, revlist |
| 52 | |
| 53 | def __init__(self, config): |
| 54 | self.config = config |
| 55 | |
| 56 | def setenv(self, env, rev): |
| 57 | env['GIT_REPO'] = self.config['git_repo'] |
| 58 | env['GIT_REV'] = rev |
| 59 | |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame^] | 60 | def fill_candidate_summary(self, summary, interesting_indexes): |
| 61 | for i in interesting_indexes: |
| 62 | rev_info = summary['rev_info'][i] |
| 63 | rev = rev_info['rev'] |
| 64 | try: |
| 65 | commit_summary = git_util.get_commit_log(self.config['git_repo'], |
| 66 | rev).splitlines()[0] |
| 67 | except subprocess.CalledProcessError: |
| 68 | logger.warning('failed to get commit log of %s at %s', rev[:10], |
| 69 | self.config['git_repo']) |
| 70 | commit_summary = '(unknown)' |
| 71 | text = 'commit %s %r' % (rev[:10], commit_summary) |
| 72 | rev_info.update({ |
| 73 | 'actions': [{ |
| 74 | 'text': text, |
| 75 | }], |
| 76 | }) |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
Kuang-che Wu | 68db08a | 2018-03-30 11:50:34 +0800 | [diff] [blame] | 80 | cli.BisectorCommandLine(GitDomain).main() |