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 |
| 16 | |
| 17 | from bisect_kit import cli |
| 18 | from bisect_kit import core |
| 19 | from bisect_kit import git_util |
| 20 | |
| 21 | |
| 22 | class GitDomain(core.BisectDomain): |
| 23 | """BisectDomain for git revisions.""" |
| 24 | revtype = staticmethod(git_util.argtype_git_rev) |
Kuang-che Wu | b237626 | 2017-11-20 18:05:24 +0800 | [diff] [blame] | 25 | help = globals()['__doc__'] |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 26 | |
| 27 | @staticmethod |
| 28 | def add_init_arguments(parser): |
| 29 | parser.add_argument( |
| 30 | '--git_repo', |
| 31 | required=True, |
| 32 | type=cli.argtype_dir_path, |
| 33 | help='Git repository path') |
| 34 | |
| 35 | @staticmethod |
| 36 | def init(opts): |
| 37 | for rev in (opts.old, opts.new): |
| 38 | if not git_util.is_containing_commit(opts.git_repo, rev): |
| 39 | raise ValueError('rev=%s is not in git_repo=%r' % (rev, opts.git_repo)) |
| 40 | |
| 41 | config = dict(git_repo=opts.git_repo) |
| 42 | revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new) |
| 43 | return config, revlist |
| 44 | |
| 45 | def __init__(self, config): |
| 46 | self.config = config |
| 47 | |
| 48 | def setenv(self, env, rev): |
| 49 | env['GIT_REPO'] = self.config['git_repo'] |
| 50 | env['GIT_REV'] = rev |
| 51 | |
Kuang-che Wu | 81aecc0 | 2018-10-31 19:37:32 +0800 | [diff] [blame] | 52 | def view(self, revlist, old, new): |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 53 | print('git log %s..%s' % (old, new)) |
| 54 | |
| 55 | |
| 56 | if __name__ == '__main__': |
Kuang-che Wu | 68db08a | 2018-03-30 11:50:34 +0800 | [diff] [blame] | 57 | cli.BisectorCommandLine(GitDomain).main() |