blob: 733fb02b465118a98a180ec2b2cdff3aeb2af9a5 [file] [log] [blame]
Kuang-che Wue41e0062017-09-01 19:04:14 +08001#!/usr/bin/env python2
2# Copyright 2017 The Chromium OS 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"""Git bisector to bisect a range of git commits.
6
7Example:
8 $ ./bisect_git.py init --old rev1 --new rev2 --git_repo /path/to/git/repo
9 $ ./bisect_git.py config switch ./switch_git.py
10 $ ./bisect_git.py config eval ./eval-manually.sh
11 $ ./bisect_git.py run
12"""
13
14from __future__ import print_function
15
16from bisect_kit import cli
17from bisect_kit import core
18from bisect_kit import git_util
19
20
21class GitDomain(core.BisectDomain):
22 """BisectDomain for git revisions."""
23 revtype = staticmethod(git_util.argtype_git_rev)
Kuang-che Wub2376262017-11-20 18:05:24 +080024 help = globals()['__doc__']
Kuang-che Wue41e0062017-09-01 19:04:14 +080025
26 @staticmethod
27 def add_init_arguments(parser):
28 parser.add_argument(
29 '--git_repo',
30 required=True,
31 type=cli.argtype_dir_path,
32 help='Git repository path')
33
34 @staticmethod
35 def init(opts):
36 for rev in (opts.old, opts.new):
37 if not git_util.is_containing_commit(opts.git_repo, rev):
38 raise ValueError('rev=%s is not in git_repo=%r' % (rev, opts.git_repo))
39
40 config = dict(git_repo=opts.git_repo)
41 revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new)
42 return config, revlist
43
44 def __init__(self, config):
45 self.config = config
46
47 def setenv(self, env, rev):
48 env['GIT_REPO'] = self.config['git_repo']
49 env['GIT_REV'] = rev
50
51 def view(self, old, new):
52 print('git log %s..%s' % (old, new))
53
54
55if __name__ == '__main__':
56 cli.BisectorCommandLineInterface(GitDomain).main()