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 2586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2597 gerrit_util.SetReview(self._GetGerritHost(), self.GetIssue(), | 2597 gerrit_util.SetReview(self._GetGerritHost(), self.GetIssue(), |
2598 labels={'Commit-Queue': vote_map[new_state]}) | 2598 labels={'Commit-Queue': vote_map[new_state]}) |
2599 | 2599 |
2600 | 2600 |
2601 _CODEREVIEW_IMPLEMENTATIONS = { | 2601 _CODEREVIEW_IMPLEMENTATIONS = { |
2602 'rietveld': _RietveldChangelistImpl, | 2602 'rietveld': _RietveldChangelistImpl, |
2603 'gerrit': _GerritChangelistImpl, | 2603 'gerrit': _GerritChangelistImpl, |
2604 } | 2604 } |
2605 | 2605 |
2606 | 2606 |
| 2607 def _add_codereview_issue_select_options(parser, extra=""): |
| 2608 _add_codereview_select_options(parser) |
| 2609 |
| 2610 text = ('Operate on this issue number instead of the current branch\'s ' |
| 2611 'implicit issue.') |
| 2612 if extra: |
| 2613 text += ' '+extra |
| 2614 parser.add_option('-i', '--issue', type=int, help=text) |
| 2615 |
| 2616 |
| 2617 def _process_codereview_issue_select_options(parser, options): |
| 2618 _process_codereview_select_options(parser, options) |
| 2619 if options.issue is not None and not options.forced_codereview: |
| 2620 parser.error('--issue must be specified with either --rietveld or --gerrit') |
| 2621 |
| 2622 |
2607 def _add_codereview_select_options(parser): | 2623 def _add_codereview_select_options(parser): |
2608 """Appends --gerrit and --rietveld options to force specific codereview.""" | 2624 """Appends --gerrit and --rietveld options to force specific codereview.""" |
2609 parser.codereview_group = optparse.OptionGroup( | 2625 parser.codereview_group = optparse.OptionGroup( |
2610 parser, 'EXPERIMENTAL! Codereview override options') | 2626 parser, 'EXPERIMENTAL! Codereview override options') |
2611 parser.add_option_group(parser.codereview_group) | 2627 parser.add_option_group(parser.codereview_group) |
2612 parser.codereview_group.add_option( | 2628 parser.codereview_group.add_option( |
2613 '--gerrit', action='store_true', | 2629 '--gerrit', action='store_true', |
2614 help='Force the use of Gerrit for codereview') | 2630 help='Force the use of Gerrit for codereview') |
2615 parser.codereview_group.add_option( | 2631 parser.codereview_group.add_option( |
2616 '--rietveld', action='store_true', | 2632 '--rietveld', action='store_true', |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3277 - Green LGTM'ed | 3293 - Green LGTM'ed |
3278 - Magenta in the commit queue | 3294 - Magenta in the commit queue |
3279 - Cyan was committed, branch can be deleted | 3295 - Cyan was committed, branch can be deleted |
3280 | 3296 |
3281 Also see 'git cl comments'. | 3297 Also see 'git cl comments'. |
3282 """ | 3298 """ |
3283 parser.add_option('--field', | 3299 parser.add_option('--field', |
3284 help='print only specific field (desc|id|patch|status|url)') | 3300 help='print only specific field (desc|id|patch|status|url)') |
3285 parser.add_option('-f', '--fast', action='store_true', | 3301 parser.add_option('-f', '--fast', action='store_true', |
3286 help='Do not retrieve review status') | 3302 help='Do not retrieve review status') |
3287 parser.add_option('-i', '--issue', type=int, | |
3288 help='Operate on this issue number instead of the current' | |
3289 ' branch\'s implicit issue. Only valid with --field.') | |
3290 parser.add_option( | 3303 parser.add_option( |
3291 '-j', '--maxjobs', action='store', type=int, | 3304 '-j', '--maxjobs', action='store', type=int, |
3292 help='The maximum number of jobs to use when retrieving review status') | 3305 help='The maximum number of jobs to use when retrieving review status') |
3293 | 3306 |
3294 auth.add_auth_options(parser) | 3307 auth.add_auth_options(parser) |
3295 _add_codereview_select_options(parser) | 3308 _add_codereview_issue_select_options( |
| 3309 parser, 'Must be in conjunction with --field.') |
3296 options, args = parser.parse_args(args) | 3310 options, args = parser.parse_args(args) |
3297 _process_codereview_select_options(parser, options) | 3311 _process_codereview_issue_select_options(parser, options) |
3298 if args: | 3312 if args: |
3299 parser.error('Unsupported args: %s' % args) | 3313 parser.error('Unsupported args: %s' % args) |
3300 auth_config = auth.extract_auth_config_from_options(options) | 3314 auth_config = auth.extract_auth_config_from_options(options) |
3301 | 3315 |
3302 if options.issue is not None: | 3316 if options.issue is not None and not options.field: |
3303 if not options.field or not options.forced_codereview: | 3317 parser.error('--field must be specified with --issue') |
3304 parser.error('--issue may only be specified in conjunction with --field' | |
3305 ' and either --rietveld or --gerrit') | |
3306 | 3318 |
3307 if options.field: | 3319 if options.field: |
3308 cl = Changelist(auth_config=auth_config, issue=options.issue, | 3320 cl = Changelist(auth_config=auth_config, issue=options.issue, |
3309 codereview=options.forced_codereview) | 3321 codereview=options.forced_codereview) |
3310 if options.field.startswith('desc'): | 3322 if options.field.startswith('desc'): |
3311 print(cl.GetDescription()) | 3323 print(cl.GetDescription()) |
3312 elif options.field == 'id': | 3324 elif options.field == 'id': |
3313 issueid = cl.GetIssue() | 3325 issueid = cl.GetIssue() |
3314 if issueid: | 3326 if issueid: |
3315 print(issueid) | 3327 print(issueid) |
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4738 return 0 | 4750 return 0 |
4739 | 4751 |
4740 | 4752 |
4741 def CMDset_commit(parser, args): | 4753 def CMDset_commit(parser, args): |
4742 """Sets the commit bit to trigger the Commit Queue.""" | 4754 """Sets the commit bit to trigger the Commit Queue.""" |
4743 parser.add_option('-d', '--dry-run', action='store_true', | 4755 parser.add_option('-d', '--dry-run', action='store_true', |
4744 help='trigger in dry run mode') | 4756 help='trigger in dry run mode') |
4745 parser.add_option('-c', '--clear', action='store_true', | 4757 parser.add_option('-c', '--clear', action='store_true', |
4746 help='stop CQ run, if any') | 4758 help='stop CQ run, if any') |
4747 auth.add_auth_options(parser) | 4759 auth.add_auth_options(parser) |
4748 _add_codereview_select_options(parser) | 4760 _add_codereview_issue_select_options(parser) |
4749 options, args = parser.parse_args(args) | 4761 options, args = parser.parse_args(args) |
4750 _process_codereview_select_options(parser, options) | 4762 _process_codereview_issue_select_options(parser, options) |
4751 auth_config = auth.extract_auth_config_from_options(options) | 4763 auth_config = auth.extract_auth_config_from_options(options) |
4752 if args: | 4764 if args: |
4753 parser.error('Unrecognized args: %s' % ' '.join(args)) | 4765 parser.error('Unrecognized args: %s' % ' '.join(args)) |
4754 if options.dry_run and options.clear: | 4766 if options.dry_run and options.clear: |
4755 parser.error('Make up your mind: both --dry-run and --clear not allowed') | 4767 parser.error('Make up your mind: both --dry-run and --clear not allowed') |
4756 | 4768 |
4757 cl = Changelist(auth_config=auth_config, codereview=options.forced_codereview) | 4769 cl = Changelist(auth_config=auth_config, issue=options.issue, |
| 4770 codereview=options.forced_codereview) |
4758 if options.clear: | 4771 if options.clear: |
4759 state = _CQState.NONE | 4772 state = _CQState.NONE |
4760 elif options.dry_run: | 4773 elif options.dry_run: |
4761 state = _CQState.DRY_RUN | 4774 state = _CQState.DRY_RUN |
4762 else: | 4775 else: |
4763 state = _CQState.COMMIT | 4776 state = _CQState.COMMIT |
4764 if not cl.GetIssue(): | 4777 if not cl.GetIssue(): |
4765 parser.error('Must upload the issue first') | 4778 parser.error('Must upload the issue first') |
4766 cl.SetCQState(state) | 4779 cl.SetCQState(state) |
4767 return 0 | 4780 return 0 |
4768 | 4781 |
4769 | 4782 |
4770 def CMDset_close(parser, args): | 4783 def CMDset_close(parser, args): |
4771 """Closes the issue.""" | 4784 """Closes the issue.""" |
| 4785 _add_codereview_issue_select_options(parser) |
4772 auth.add_auth_options(parser) | 4786 auth.add_auth_options(parser) |
4773 options, args = parser.parse_args(args) | 4787 options, args = parser.parse_args(args) |
| 4788 _process_codereview_issue_select_options(parser, options) |
4774 auth_config = auth.extract_auth_config_from_options(options) | 4789 auth_config = auth.extract_auth_config_from_options(options) |
4775 if args: | 4790 if args: |
4776 parser.error('Unrecognized args: %s' % ' '.join(args)) | 4791 parser.error('Unrecognized args: %s' % ' '.join(args)) |
4777 cl = Changelist(auth_config=auth_config) | 4792 cl = Changelist(auth_config=auth_config, issue=options.issue, |
| 4793 codereview=options.forced_codereview) |
4778 # Ensure there actually is an issue to close. | 4794 # Ensure there actually is an issue to close. |
4779 cl.GetDescription() | 4795 cl.GetDescription() |
4780 cl.CloseIssue() | 4796 cl.CloseIssue() |
4781 return 0 | 4797 return 0 |
4782 | 4798 |
4783 | 4799 |
4784 def CMDdiff(parser, args): | 4800 def CMDdiff(parser, args): |
4785 """Shows differences between local tree and last upload.""" | 4801 """Shows differences between local tree and last upload.""" |
4786 auth.add_auth_options(parser) | 4802 auth.add_auth_options(parser) |
4787 options, args = parser.parse_args(args) | 4803 options, args = parser.parse_args(args) |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5126 if __name__ == '__main__': | 5142 if __name__ == '__main__': |
5127 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5143 # These affect sys.stdout so do it outside of main() to simplify mocks in |
5128 # unit testing. | 5144 # unit testing. |
5129 fix_encoding.fix_encoding() | 5145 fix_encoding.fix_encoding() |
5130 setup_color.init() | 5146 setup_color.init() |
5131 try: | 5147 try: |
5132 sys.exit(main(sys.argv[1:])) | 5148 sys.exit(main(sys.argv[1:])) |
5133 except KeyboardInterrupt: | 5149 except KeyboardInterrupt: |
5134 sys.stderr.write('interrupted\n') | 5150 sys.stderr.write('interrupted\n') |
5135 sys.exit(1) | 5151 sys.exit(1) |
OLD | NEW |