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 distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 3261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3272 with open(options.json_file, 'wb') as f: | 3272 with open(options.json_file, 'wb') as f: |
3273 json.dump(summary, f) | 3273 json.dump(summary, f) |
3274 return 0 | 3274 return 0 |
3275 | 3275 |
3276 | 3276 |
3277 @subcommand.usage('[codereview url or issue id]') | 3277 @subcommand.usage('[codereview url or issue id]') |
3278 def CMDdescription(parser, args): | 3278 def CMDdescription(parser, args): |
3279 """Brings up the editor for the current CL's description.""" | 3279 """Brings up the editor for the current CL's description.""" |
3280 parser.add_option('-d', '--display', action='store_true', | 3280 parser.add_option('-d', '--display', action='store_true', |
3281 help='Display the description instead of opening an editor') | 3281 help='Display the description instead of opening an editor') |
| 3282 parser.add_option('-n', '--new-description', |
| 3283 help='New description to set for this issue (- for stdin)') |
3282 | 3284 |
3283 _add_codereview_select_options(parser) | 3285 _add_codereview_select_options(parser) |
3284 auth.add_auth_options(parser) | 3286 auth.add_auth_options(parser) |
3285 options, args = parser.parse_args(args) | 3287 options, args = parser.parse_args(args) |
3286 _process_codereview_select_options(parser, options) | 3288 _process_codereview_select_options(parser, options) |
3287 | 3289 |
3288 target_issue = None | 3290 target_issue = None |
3289 if len(args) > 0: | 3291 if len(args) > 0: |
3290 issue_arg = ParseIssueNumberArgument(args[0]) | 3292 issue_arg = ParseIssueNumberArgument(args[0]) |
3291 if not issue_arg.valid: | 3293 if not issue_arg.valid: |
3292 parser.print_help() | 3294 parser.print_help() |
3293 return 1 | 3295 return 1 |
3294 target_issue = issue_arg.issue | 3296 target_issue = issue_arg.issue |
3295 | 3297 |
3296 auth_config = auth.extract_auth_config_from_options(options) | 3298 auth_config = auth.extract_auth_config_from_options(options) |
3297 | 3299 |
3298 cl = Changelist( | 3300 cl = Changelist( |
3299 auth_config=auth_config, issue=target_issue, | 3301 auth_config=auth_config, issue=target_issue, |
3300 codereview=options.forced_codereview) | 3302 codereview=options.forced_codereview) |
3301 | 3303 |
3302 if not cl.GetIssue(): | 3304 if not cl.GetIssue(): |
3303 DieWithError('This branch has no associated changelist.') | 3305 DieWithError('This branch has no associated changelist.') |
3304 description = ChangeDescription(cl.GetDescription()) | 3306 description = ChangeDescription(cl.GetDescription()) |
| 3307 |
3305 if options.display: | 3308 if options.display: |
3306 print description.description | 3309 print description.description |
3307 return 0 | 3310 return 0 |
3308 description.prompt() | 3311 |
| 3312 if options.new_description: |
| 3313 text = options.new_description |
| 3314 if text == '-': |
| 3315 text = '\n'.join(l.rstrip() for l in sys.stdin) |
| 3316 |
| 3317 description.set_description(text) |
| 3318 else: |
| 3319 description.prompt() |
| 3320 |
3309 if cl.GetDescription() != description.description: | 3321 if cl.GetDescription() != description.description: |
3310 cl.UpdateDescription(description.description) | 3322 cl.UpdateDescription(description.description) |
3311 return 0 | 3323 return 0 |
3312 | 3324 |
3313 | 3325 |
3314 def CreateDescriptionFromLog(args): | 3326 def CreateDescriptionFromLog(args): |
3315 """Pulls out the commit log to use as a base for the CL description.""" | 3327 """Pulls out the commit log to use as a base for the CL description.""" |
3316 log_args = [] | 3328 log_args = [] |
3317 if len(args) == 1 and not args[0].endswith('.'): | 3329 if len(args) == 1 and not args[0].endswith('.'): |
3318 log_args = [args[0] + '..'] | 3330 log_args = [args[0] + '..'] |
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4865 if __name__ == '__main__': | 4877 if __name__ == '__main__': |
4866 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4878 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4867 # unit testing. | 4879 # unit testing. |
4868 fix_encoding.fix_encoding() | 4880 fix_encoding.fix_encoding() |
4869 setup_color.init() | 4881 setup_color.init() |
4870 try: | 4882 try: |
4871 sys.exit(main(sys.argv[1:])) | 4883 sys.exit(main(sys.argv[1:])) |
4872 except KeyboardInterrupt: | 4884 except KeyboardInterrupt: |
4873 sys.stderr.write('interrupted\n') | 4885 sys.stderr.write('interrupted\n') |
4874 sys.exit(1) | 4886 sys.exit(1) |
OLD | NEW |