Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | r"""Switcher for git bisecting. |
| 6 | |
| 7 | Typical usage: |
| 8 | $ bisect_git.py config switch ./switch_git.py |
| 9 | |
| 10 | This is actually equivalent to |
| 11 | $ bisect_git.py config switch \ |
| 12 | sh -c 'cd $GIT_REPO && git checkout -q -f $GIT_REV' |
| 13 | (Note, use single quotes instead of double quotes because the variables need to |
| 14 | be expanded at switch time, not now.) |
| 15 | """ |
| 16 | from __future__ import print_function |
| 17 | import argparse |
| 18 | import logging |
| 19 | |
| 20 | from bisect_kit import cli |
| 21 | from bisect_kit import common |
| 22 | from bisect_kit import git_util |
| 23 | from bisect_kit import util |
| 24 | |
| 25 | logger = logging.getLogger(__name__) |
| 26 | |
| 27 | |
| 28 | def create_argument_parser(): |
| 29 | defaults = util.DefaultConfig() |
| 30 | parser = argparse.ArgumentParser() |
| 31 | common.add_logging_arguments(parser, defaults) |
| 32 | parser.add_argument( |
| 33 | 'git_rev', |
| 34 | nargs='?', |
| 35 | type=git_util.argtype_git_rev, |
| 36 | metavar='GIT_REV', |
| 37 | default=defaults.get('GIT_REV', ''), |
| 38 | help='Git revision id') |
| 39 | parser.add_argument( |
| 40 | '--git_repo', |
| 41 | type=cli.argtype_dir_path, |
| 42 | metavar='GIT_REPO', |
| 43 | default=defaults.get('GIT_REPO'), |
| 44 | help='Git repository path') |
| 45 | |
| 46 | return parser |
| 47 | |
| 48 | |
| 49 | def main(args=None): |
| 50 | parser = create_argument_parser() |
| 51 | opts = parser.parse_args(args) |
| 52 | common.config_logging(opts) |
| 53 | |
| 54 | git_util.checkout_version(opts.git_repo, opts.git_rev) |
| 55 | |
| 56 | |
| 57 | if __name__ == '__main__': |
| 58 | main() |