blob: 6d3eb650fb54f17ca560e2b1aa6680eef696cb89 [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)
24
25 @staticmethod
26 def add_init_arguments(parser):
27 parser.add_argument(
28 '--git_repo',
29 required=True,
30 type=cli.argtype_dir_path,
31 help='Git repository path')
32
33 @staticmethod
34 def init(opts):
35 for rev in (opts.old, opts.new):
36 if not git_util.is_containing_commit(opts.git_repo, rev):
37 raise ValueError('rev=%s is not in git_repo=%r' % (rev, opts.git_repo))
38
39 config = dict(git_repo=opts.git_repo)
40 revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new)
41 return config, revlist
42
43 def __init__(self, config):
44 self.config = config
45
46 def setenv(self, env, rev):
47 env['GIT_REPO'] = self.config['git_repo']
48 env['GIT_REV'] = rev
49
50 def view(self, old, new):
51 print('git log %s..%s' % (old, new))
52
53
54if __name__ == '__main__':
55 cli.BisectorCommandLineInterface(GitDomain).main()