blob: 4846dc8b56634f70c9c4203d9216036299b7b4e4 [file] [log] [blame]
Kuang-che Wue41e0062017-09-01 19:04:14 +08001#!/usr/bin/env python2
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wue41e0062017-09-01 19:04:14 +08003# 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
8Example:
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
15from __future__ import print_function
16
17from bisect_kit import cli
18from bisect_kit import core
Kuang-che Wue121fae2018-11-09 16:18:39 +080019from bisect_kit import errors
Kuang-che Wue41e0062017-09-01 19:04:14 +080020from bisect_kit import git_util
21
22
23class GitDomain(core.BisectDomain):
24 """BisectDomain for git revisions."""
25 revtype = staticmethod(git_util.argtype_git_rev)
Kuang-che Wub2376262017-11-20 18:05:24 +080026 help = globals()['__doc__']
Kuang-che Wue41e0062017-09-01 19:04:14 +080027
28 @staticmethod
29 def add_init_arguments(parser):
30 parser.add_argument(
31 '--git_repo',
32 required=True,
33 type=cli.argtype_dir_path,
34 help='Git repository path')
35
36 @staticmethod
37 def init(opts):
Kuang-che Wue121fae2018-11-09 16:18:39 +080038 if not git_util.is_containing_commit(opts.git_repo, opts.old):
39 raise errors.ArgumentError(
40 '--old', '%s is not in git_repo=%r' % (opts.old, opts.git_repo))
41 if not git_util.is_containing_commit(opts.git_repo, opts.new):
42 raise errors.ArgumentError(
43 '--new', '%s is not in git_repo=%r' % (opts.new, opts.git_repo))
Kuang-che Wue41e0062017-09-01 19:04:14 +080044
45 config = dict(git_repo=opts.git_repo)
46 revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new)
47 return config, revlist
48
49 def __init__(self, config):
50 self.config = config
51
52 def setenv(self, env, rev):
53 env['GIT_REPO'] = self.config['git_repo']
54 env['GIT_REV'] = rev
55
Kuang-che Wu81aecc02018-10-31 19:37:32 +080056 def view(self, revlist, old, new):
Kuang-che Wue41e0062017-09-01 19:04:14 +080057 print('git log %s..%s' % (old, new))
58
59
60if __name__ == '__main__':
Kuang-che Wu68db08a2018-03-30 11:50:34 +080061 cli.BisectorCommandLine(GitDomain).main()