| #!/usr/bin/env python3 |
| # -*- coding: utf-8 -*- |
| # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """Git bisector to bisect a range of git commits. |
| |
| Example: |
| $ ./bisect_git.py init --old rev1 --new rev2 --git_repo /path/to/git/repo |
| $ ./bisect_git.py config switch ./switch_git.py |
| $ ./bisect_git.py config eval ./eval-manually.sh |
| $ ./bisect_git.py run |
| """ |
| |
| from __future__ import print_function |
| import logging |
| |
| from bisect_kit import bisector_cli |
| from bisect_kit import cli |
| from bisect_kit import core |
| from bisect_kit import errors |
| from bisect_kit import git_util |
| |
| logger = logging.getLogger(__name__) |
| |
| |
| class GitDomain(core.BisectDomain): |
| """BisectDomain for git revisions.""" |
| revtype = staticmethod(cli.argtype_notempty) |
| help = globals()['__doc__'] |
| |
| @staticmethod |
| def add_init_arguments(parser): |
| parser.add_argument( |
| '--git_repo', |
| required=True, |
| type=cli.argtype_dir_path, |
| help='Git repository path') |
| |
| @staticmethod |
| def init(opts): |
| try: |
| opts.old = git_util.get_commit_hash(opts.git_repo, opts.old) |
| except ValueError as e: |
| raise errors.ArgumentError('--old', str(e)) |
| try: |
| opts.new = git_util.get_commit_hash(opts.git_repo, opts.new) |
| except ValueError as e: |
| raise errors.ArgumentError('--new', str(e)) |
| |
| config = dict(git_repo=opts.git_repo) |
| revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new) |
| |
| details = {} |
| metas = git_util.get_batch_commit_metadata(opts.git_repo, revlist) |
| for rev in revlist: |
| meta = metas[rev] |
| if meta is None: |
| commit_summary = '(unknown)' |
| else: |
| commit_summary = meta['message'].splitlines()[0] |
| action = {'rev': rev, 'commit_summary': commit_summary} |
| details[rev] = {'actions': [action]} |
| |
| return config, {'revlist': revlist} |
| |
| def __init__(self, config): |
| self.config = config |
| |
| def setenv(self, env, rev): |
| env['GIT_REPO'] = self.config['git_repo'] |
| env['GIT_REV'] = rev |
| |
| def fill_candidate_summary(self, summary): |
| # Do nothing. |
| pass |
| |
| |
| if __name__ == '__main__': |
| bisector_cli.BisectorCommandLine(GitDomain).main() |