OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
9 | 9 |
10 from __future__ import print_function | 10 from __future__ import print_function |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 stdout=stdout, env=env) | 643 stdout=stdout, env=env) |
644 | 644 |
645 | 645 |
646 class BuildbucketResponseException(Exception): | 646 class BuildbucketResponseException(Exception): |
647 pass | 647 pass |
648 | 648 |
649 | 649 |
650 class Settings(object): | 650 class Settings(object): |
651 def __init__(self): | 651 def __init__(self): |
652 self.default_server = None | 652 self.default_server = None |
| 653 self.server_override = None |
653 self.cc = None | 654 self.cc = None |
654 self.root = None | 655 self.root = None |
655 self.is_git_svn = None | 656 self.is_git_svn = None |
656 self.svn_branch = None | 657 self.svn_branch = None |
657 self.tree_status_url = None | 658 self.tree_status_url = None |
658 self.viewvc_url = None | 659 self.viewvc_url = None |
659 self.updated = False | 660 self.updated = False |
660 self.is_gerrit = None | 661 self.is_gerrit = None |
661 self.squash_gerrit_uploads = None | 662 self.squash_gerrit_uploads = None |
662 self.gerrit_skip_ensure_authenticated = None | 663 self.gerrit_skip_ensure_authenticated = None |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 assert settings, 'must be initialized in _ChangelistCodereviewBase' | 1732 assert settings, 'must be initialized in _ChangelistCodereviewBase' |
1732 if not rietveld_server: | 1733 if not rietveld_server: |
1733 settings.GetDefaultServerUrl() | 1734 settings.GetDefaultServerUrl() |
1734 | 1735 |
1735 self._rietveld_server = rietveld_server | 1736 self._rietveld_server = rietveld_server |
1736 self._auth_config = auth_config | 1737 self._auth_config = auth_config |
1737 self._props = None | 1738 self._props = None |
1738 self._rpc_server = None | 1739 self._rpc_server = None |
1739 | 1740 |
1740 def GetCodereviewServer(self): | 1741 def GetCodereviewServer(self): |
| 1742 global settings |
| 1743 if settings and settings.server_override: |
| 1744 return gclient_utils.UpgradeToHttps(settings.server_override) |
| 1745 |
1741 if not self._rietveld_server: | 1746 if not self._rietveld_server: |
1742 # If we're on a branch then get the server potentially associated | 1747 # If we're on a branch then get the server potentially associated |
1743 # with that branch. | 1748 # with that branch. |
1744 if self.GetIssue(): | 1749 if self.GetIssue(): |
1745 self._rietveld_server = gclient_utils.UpgradeToHttps( | 1750 self._rietveld_server = gclient_utils.UpgradeToHttps( |
1746 self._GitGetBranchConfigValue(self.CodereviewServerConfigKey())) | 1751 self._GitGetBranchConfigValue(self.CodereviewServerConfigKey())) |
1747 if not self._rietveld_server: | 1752 if not self._rietveld_server: |
1748 self._rietveld_server = settings.GetDefaultServerUrl() | 1753 self._rietveld_server = settings.GetDefaultServerUrl() |
1749 return self._rietveld_server | 1754 return self._rietveld_server |
1750 | 1755 |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 ' Your current remote is: %s' % self.GetRemoteUrl()) | 2209 ' Your current remote is: %s' % self.GetRemoteUrl()) |
2205 self._gerrit_host = '%s.googlesource.com' % self._gerrit_host | 2210 self._gerrit_host = '%s.googlesource.com' % self._gerrit_host |
2206 self._gerrit_server = 'https://%s' % self._gerrit_host | 2211 self._gerrit_server = 'https://%s' % self._gerrit_host |
2207 return self._gerrit_host | 2212 return self._gerrit_host |
2208 | 2213 |
2209 def _GetGitHost(self): | 2214 def _GetGitHost(self): |
2210 """Returns git host to be used when uploading change to Gerrit.""" | 2215 """Returns git host to be used when uploading change to Gerrit.""" |
2211 return urlparse.urlparse(self.GetRemoteUrl()).netloc | 2216 return urlparse.urlparse(self.GetRemoteUrl()).netloc |
2212 | 2217 |
2213 def GetCodereviewServer(self): | 2218 def GetCodereviewServer(self): |
| 2219 global settings |
| 2220 if settings and settings.server_override: |
| 2221 return gclient_utils.UpgradeToHttps(settings.server_override) |
| 2222 |
2214 if not self._gerrit_server: | 2223 if not self._gerrit_server: |
2215 # If we're on a branch then get the server potentially associated | 2224 # If we're on a branch then get the server potentially associated |
2216 # with that branch. | 2225 # with that branch. |
2217 if self.GetIssue(): | 2226 if self.GetIssue(): |
2218 self._gerrit_server = self._GitGetBranchConfigValue( | 2227 self._gerrit_server = self._GitGetBranchConfigValue( |
2219 self.CodereviewServerConfigKey()) | 2228 self.CodereviewServerConfigKey()) |
2220 if self._gerrit_server: | 2229 if self._gerrit_server: |
2221 self._gerrit_host = urlparse.urlparse(self._gerrit_server).netloc | 2230 self._gerrit_host = urlparse.urlparse(self._gerrit_server).netloc |
2222 if not self._gerrit_server: | 2231 if not self._gerrit_server: |
2223 # We assume repo to be hosted on Gerrit, and hence Gerrit server | 2232 # We assume repo to be hosted on Gerrit, and hence Gerrit server |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2812 """Appends --gerrit and --rietveld options to force specific codereview.""" | 2821 """Appends --gerrit and --rietveld options to force specific codereview.""" |
2813 parser.codereview_group = optparse.OptionGroup( | 2822 parser.codereview_group = optparse.OptionGroup( |
2814 parser, 'EXPERIMENTAL! Codereview override options') | 2823 parser, 'EXPERIMENTAL! Codereview override options') |
2815 parser.add_option_group(parser.codereview_group) | 2824 parser.add_option_group(parser.codereview_group) |
2816 parser.codereview_group.add_option( | 2825 parser.codereview_group.add_option( |
2817 '--gerrit', action='store_true', | 2826 '--gerrit', action='store_true', |
2818 help='Force the use of Gerrit for codereview') | 2827 help='Force the use of Gerrit for codereview') |
2819 parser.codereview_group.add_option( | 2828 parser.codereview_group.add_option( |
2820 '--rietveld', action='store_true', | 2829 '--rietveld', action='store_true', |
2821 help='Force the use of Rietveld for codereview') | 2830 help='Force the use of Rietveld for codereview') |
| 2831 parser.codereview_group.add_option( |
| 2832 '--force-codereview-server', action='store', metavar='URL', |
| 2833 help='Use this codereview server instead of the default.') |
2822 | 2834 |
2823 | 2835 |
2824 def _process_codereview_select_options(parser, options): | 2836 def _process_codereview_select_options(parser, options): |
2825 if options.gerrit and options.rietveld: | 2837 if options.gerrit and options.rietveld: |
2826 parser.error('Options --gerrit and --rietveld are mutually exclusive') | 2838 parser.error('Options --gerrit and --rietveld are mutually exclusive') |
2827 options.forced_codereview = None | 2839 options.forced_codereview = None |
2828 if options.gerrit: | 2840 if options.gerrit: |
2829 options.forced_codereview = 'gerrit' | 2841 options.forced_codereview = 'gerrit' |
2830 elif options.rietveld: | 2842 elif options.rietveld: |
2831 options.forced_codereview = 'rietveld' | 2843 options.forced_codereview = 'rietveld' |
2832 | 2844 |
| 2845 if options.force_codereview_server: |
| 2846 global settings |
| 2847 if settings: |
| 2848 settings.server_override = options.force_codereview_server |
| 2849 |
2833 | 2850 |
2834 def _get_bug_line_values(default_project, bugs): | 2851 def _get_bug_line_values(default_project, bugs): |
2835 """Given default_project and comma separated list of bugs, yields bug line | 2852 """Given default_project and comma separated list of bugs, yields bug line |
2836 values. | 2853 values. |
2837 | 2854 |
2838 Each bug can be either: | 2855 Each bug can be either: |
2839 * a number, which is combined with default_project | 2856 * a number, which is combined with default_project |
2840 * string, which is left as is. | 2857 * string, which is left as is. |
2841 | 2858 |
2842 This function may produce more than one line, because bugdroid expects one | 2859 This function may produce more than one line, because bugdroid expects one |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3511 help='Do not retrieve review status') | 3528 help='Do not retrieve review status') |
3512 parser.add_option( | 3529 parser.add_option( |
3513 '-j', '--maxjobs', action='store', type=int, | 3530 '-j', '--maxjobs', action='store', type=int, |
3514 help='The maximum number of jobs to use when retrieving review status') | 3531 help='The maximum number of jobs to use when retrieving review status') |
3515 | 3532 |
3516 auth.add_auth_options(parser) | 3533 auth.add_auth_options(parser) |
3517 _add_codereview_issue_select_options( | 3534 _add_codereview_issue_select_options( |
3518 parser, 'Must be in conjunction with --field.') | 3535 parser, 'Must be in conjunction with --field.') |
3519 options, args = parser.parse_args(args) | 3536 options, args = parser.parse_args(args) |
3520 _process_codereview_issue_select_options(parser, options) | 3537 _process_codereview_issue_select_options(parser, options) |
| 3538 _process_codereview_select_options(parser, options) |
3521 if args: | 3539 if args: |
3522 parser.error('Unsupported args: %s' % args) | 3540 parser.error('Unsupported args: %s' % args) |
3523 auth_config = auth.extract_auth_config_from_options(options) | 3541 auth_config = auth.extract_auth_config_from_options(options) |
3524 | 3542 |
3525 if options.issue is not None and not options.field: | 3543 if options.issue is not None and not options.field: |
3526 parser.error('--field must be specified with --issue') | 3544 parser.error('--field must be specified with --issue') |
3527 | 3545 |
3528 if options.field: | 3546 if options.field: |
3529 cl = Changelist(auth_config=auth_config, issue=options.issue, | 3547 cl = Changelist(auth_config=auth_config, issue=options.issue, |
3530 codereview=options.forced_codereview) | 3548 codereview=options.forced_codereview) |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5373 if __name__ == '__main__': | 5391 if __name__ == '__main__': |
5374 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5392 # These affect sys.stdout so do it outside of main() to simplify mocks in |
5375 # unit testing. | 5393 # unit testing. |
5376 fix_encoding.fix_encoding() | 5394 fix_encoding.fix_encoding() |
5377 setup_color.init() | 5395 setup_color.init() |
5378 try: | 5396 try: |
5379 sys.exit(main(sys.argv[1:])) | 5397 sys.exit(main(sys.argv[1:])) |
5380 except KeyboardInterrupt: | 5398 except KeyboardInterrupt: |
5381 sys.stderr.write('interrupted\n') | 5399 sys.stderr.write('interrupted\n') |
5382 sys.exit(1) | 5400 sys.exit(1) |
OLD | NEW |