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 | r"""Switcher for git bisecting. |
| 7 | |
| 8 | Typical usage: |
| 9 | $ bisect_git.py config switch ./switch_git.py |
| 10 | |
| 11 | This is actually equivalent to |
| 12 | $ bisect_git.py config switch \ |
| 13 | sh -c 'cd $GIT_REPO && git checkout -q -f $GIT_REV' |
| 14 | (Note, use single quotes instead of double quotes because the variables need to |
| 15 | be expanded at switch time, not now.) |
| 16 | """ |
| 17 | from __future__ import print_function |
| 18 | import argparse |
| 19 | import logging |
| 20 | |
| 21 | from bisect_kit import cli |
| 22 | from bisect_kit import common |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 23 | from bisect_kit import configure |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 24 | from bisect_kit import git_util |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 25 | |
| 26 | logger = logging.getLogger(__name__) |
| 27 | |
| 28 | |
| 29 | def create_argument_parser(): |
Kuang-che Wu | d2d6e41 | 2021-01-28 16:26:41 +0800 | [diff] [blame] | 30 | parents = [common.common_argument_parser, common.session_optional_parser] |
| 31 | parser = argparse.ArgumentParser(parents=parents) |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 32 | cli.patching_argparser_exit(parser) |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 33 | parser.add_argument( |
| 34 | 'git_rev', |
| 35 | nargs='?', |
| 36 | type=git_util.argtype_git_rev, |
| 37 | metavar='GIT_REV', |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 38 | default=configure.get('GIT_REV', ''), |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 39 | help='Git revision id') |
| 40 | parser.add_argument( |
| 41 | '--git_repo', |
| 42 | type=cli.argtype_dir_path, |
| 43 | metavar='GIT_REPO', |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 44 | default=configure.get('GIT_REPO'), |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 45 | help='Git repository path') |
| 46 | |
| 47 | return parser |
| 48 | |
| 49 | |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 50 | @cli.fatal_error_handler |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 51 | def main(args=None): |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 52 | common.init() |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 53 | parser = create_argument_parser() |
| 54 | opts = parser.parse_args(args) |
| 55 | common.config_logging(opts) |
| 56 | |
| 57 | git_util.checkout_version(opts.git_repo, opts.git_rev) |
| 58 | |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 | main() |