blob: 7be641d0d3e852b9a4f8be78ad34c2eac8bfebd7 [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
19from bisect_kit import git_util
20
21
22class GitDomain(core.BisectDomain):
23 """BisectDomain for git revisions."""
24 revtype = staticmethod(git_util.argtype_git_rev)
Kuang-che Wub2376262017-11-20 18:05:24 +080025 help = globals()['__doc__']
Kuang-che Wue41e0062017-09-01 19:04:14 +080026
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 Wu81aecc02018-10-31 19:37:32 +080052 def view(self, revlist, old, new):
Kuang-che Wue41e0062017-09-01 19:04:14 +080053 print('git log %s..%s' % (old, new))
54
55
56if __name__ == '__main__':
Kuang-che Wu68db08a2018-03-30 11:50:34 +080057 cli.BisectorCommandLine(GitDomain).main()