Kuang-che Wu | 875c89a | 2020-01-08 14:30:55 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 3 | # 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 | |
| 8 | Example: |
| 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 | |
| 15 | from __future__ import print_function |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 16 | import logging |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 17 | |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 18 | from bisect_kit import bisector_cli |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 19 | from bisect_kit import cli |
| 20 | from bisect_kit import core |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 21 | from bisect_kit import errors |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 22 | from bisect_kit import git_util |
| 23 | |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 24 | logger = logging.getLogger(__name__) |
| 25 | |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 26 | |
| 27 | class GitDomain(core.BisectDomain): |
| 28 | """BisectDomain for git revisions.""" |
Kuang-che Wu | 5e7c9b0 | 2019-01-03 21:16:01 +0800 | [diff] [blame] | 29 | revtype = staticmethod(cli.argtype_notempty) |
Kuang-che Wu | b237626 | 2017-11-20 18:05:24 +0800 | [diff] [blame] | 30 | help = globals()['__doc__'] |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 31 | |
| 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 Wu | 5e7c9b0 | 2019-01-03 21:16:01 +0800 | [diff] [blame] | 42 | try: |
| 43 | opts.old = git_util.get_commit_hash(opts.git_repo, opts.old) |
| 44 | except ValueError as e: |
Kuang-che Wu | a7ddf9b | 2019-11-25 18:59:57 +0800 | [diff] [blame] | 45 | raise errors.ArgumentError('--old', str(e)) |
Kuang-che Wu | 5e7c9b0 | 2019-01-03 21:16:01 +0800 | [diff] [blame] | 46 | try: |
| 47 | opts.new = git_util.get_commit_hash(opts.git_repo, opts.new) |
| 48 | except ValueError as e: |
Kuang-che Wu | a7ddf9b | 2019-11-25 18:59:57 +0800 | [diff] [blame] | 49 | raise errors.ArgumentError('--new', str(e)) |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 50 | |
| 51 | config = dict(git_repo=opts.git_repo) |
| 52 | revlist = git_util.get_revlist(opts.git_repo, opts.old, opts.new) |
Kuang-che Wu | 13acc7b | 2020-06-15 10:45:35 +0800 | [diff] [blame] | 53 | |
| 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 Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 66 | |
| 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 Wu | 13acc7b | 2020-06-15 10:45:35 +0800 | [diff] [blame] | 74 | def fill_candidate_summary(self, summary): |
| 75 | # Do nothing. |
| 76 | pass |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 80 | bisector_cli.BisectorCommandLine(GitDomain).main() |