blob: d6d8de9b3a80eb06b7b51bb80f14359a6bbf524c [file] [log] [blame]
Kuang-che Wu875c89a2020-01-08 14:30:55 +08001#!/usr/bin/env python3
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
Kuang-che Wue80bb872018-11-15 19:45:25 +080016import logging
Kuang-che Wue41e0062017-09-01 19:04:14 +080017
Kuang-che Wu2526a672019-09-10 16:23:59 +080018from bisect_kit import bisector_cli
Kuang-che Wue41e0062017-09-01 19:04:14 +080019from bisect_kit import cli
20from bisect_kit import core
Kuang-che Wue121fae2018-11-09 16:18:39 +080021from bisect_kit import errors
Kuang-che Wue41e0062017-09-01 19:04:14 +080022from bisect_kit import git_util
23
Kuang-che Wue80bb872018-11-15 19:45:25 +080024logger = logging.getLogger(__name__)
25
Kuang-che Wue41e0062017-09-01 19:04:14 +080026
27class GitDomain(core.BisectDomain):
28 """BisectDomain for git revisions."""
Kuang-che Wu5e7c9b02019-01-03 21:16:01 +080029 revtype = staticmethod(cli.argtype_notempty)
Kuang-che Wub2376262017-11-20 18:05:24 +080030 help = globals()['__doc__']
Kuang-che Wue41e0062017-09-01 19:04:14 +080031
32 @staticmethod
33 def add_init_arguments(parser):
34 parser.add_argument(
35 '--git_repo',
36 required=True,
37 type=cli.argtype_dir_path,
38 help='Git repository path')
39
40 @staticmethod
41 def init(opts):
Kuang-che Wu5e7c9b02019-01-03 21:16:01 +080042 try:
43 opts.old = git_util.get_commit_hash(opts.git_repo, opts.old)
44 except ValueError as e:
Kuang-che Wua7ddf9b2019-11-25 18:59:57 +080045 raise errors.ArgumentError('--old', str(e))
Kuang-che Wu5e7c9b02019-01-03 21:16:01 +080046 try:
47 opts.new = git_util.get_commit_hash(opts.git_repo, opts.new)
48 except ValueError as e:
Kuang-che Wua7ddf9b2019-11-25 18:59:57 +080049 raise errors.ArgumentError('--new', str(e))
Kuang-che Wue41e0062017-09-01 19:04:14 +080050
51 config = dict(git_repo=opts.git_repo)
52 revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new)
Kuang-che Wu13acc7b2020-06-15 10:45:35 +080053
54 details = {}
55 metas = git_util.get_batch_commit_metadata(opts.git_repo, revlist)
56 for rev in revlist:
57 meta = metas[rev]
58 if meta is None:
59 commit_summary = '(unknown)'
60 else:
61 commit_summary = meta['message'].splitlines()[0]
62 action = {'rev': rev, 'commit_summary': commit_summary}
63 details[rev] = {'actions': [action]}
64
65 return config, {'revlist': revlist}
Kuang-che Wue41e0062017-09-01 19:04:14 +080066
67 def __init__(self, config):
68 self.config = config
69
70 def setenv(self, env, rev):
71 env['GIT_REPO'] = self.config['git_repo']
72 env['GIT_REV'] = rev
73
Kuang-che Wu13acc7b2020-06-15 10:45:35 +080074 def fill_candidate_summary(self, summary):
75 # Do nothing.
76 pass
Kuang-che Wue41e0062017-09-01 19:04:14 +080077
78
79if __name__ == '__main__':
Kuang-che Wu2526a672019-09-10 16:23:59 +080080 bisector_cli.BisectorCommandLine(GitDomain).main()