Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
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 | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 30 | parser = argparse.ArgumentParser() |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 31 | common.add_common_arguments(parser) |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 32 | parser.add_argument( |
| 33 | 'git_rev', |
| 34 | nargs='?', |
| 35 | type=git_util.argtype_git_rev, |
| 36 | metavar='GIT_REV', |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 37 | default=configure.get('GIT_REV', ''), |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 38 | help='Git revision id') |
| 39 | parser.add_argument( |
| 40 | '--git_repo', |
| 41 | type=cli.argtype_dir_path, |
| 42 | metavar='GIT_REPO', |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 43 | default=configure.get('GIT_REPO'), |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 44 | help='Git repository path') |
| 45 | |
| 46 | return parser |
| 47 | |
| 48 | |
| 49 | def main(args=None): |
Kuang-che Wu | 385279d | 2017-09-27 14:48:28 +0800 | [diff] [blame] | 50 | common.init() |
Kuang-che Wu | e41e006 | 2017-09-01 19:04:14 +0800 | [diff] [blame] | 51 | parser = create_argument_parser() |
| 52 | opts = parser.parse_args(args) |
| 53 | common.config_logging(opts) |
| 54 | |
| 55 | git_util.checkout_version(opts.git_repo, opts.git_rev) |
| 56 | |
| 57 | |
| 58 | if __name__ == '__main__': |
| 59 | main() |