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.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 import logging | 10 import logging |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL', | 632 SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL', |
633 'tree-status-url', False) | 633 'tree-status-url', False) |
634 SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True) | 634 SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True) |
635 | 635 |
636 # TODO: configure a default branch to diff against, rather than this | 636 # TODO: configure a default branch to diff against, rather than this |
637 # svn-based hackery. | 637 # svn-based hackery. |
638 | 638 |
639 | 639 |
640 class ChangeDescription(object): | 640 class ChangeDescription(object): |
641 """Contains a parsed form of the change description.""" | 641 """Contains a parsed form of the change description.""" |
642 def __init__(self, log_desc, reviewers): | 642 def __init__(self, subject, log_desc, reviewers): |
| 643 self.subject = subject |
643 self.log_desc = log_desc | 644 self.log_desc = log_desc |
644 self.reviewers = reviewers | 645 self.reviewers = reviewers |
645 self.description = self.log_desc | 646 self.description = self.log_desc |
646 | 647 |
647 def Prompt(self): | 648 def Update(self): |
648 content = """# Enter a description of the change. | 649 initial_text = """# Enter a description of the change. |
649 # This will displayed on the codereview site. | 650 # This will displayed on the codereview site. |
650 # The first line will also be used as the subject of the review. | 651 # The first line will also be used as the subject of the review. |
651 """ | 652 """ |
652 content += self.description | 653 initial_text += self.description |
653 if ('\nR=' not in self.description and | 654 if ('\nR=' not in self.description and |
654 '\nTBR=' not in self.description and | 655 '\nTBR=' not in self.description and |
655 self.reviewers): | 656 self.reviewers): |
656 content += '\nR=' + self.reviewers | 657 initial_text += '\nR=' + self.reviewers |
657 if '\nBUG=' not in self.description: | 658 if '\nBUG=' not in self.description: |
658 content += '\nBUG=' | 659 initial_text += '\nBUG=' |
659 if '\nTEST=' not in self.description: | 660 if '\nTEST=' not in self.description: |
660 content += '\nTEST=' | 661 initial_text += '\nTEST=' |
661 content = content.rstrip('\n') + '\n' | 662 initial_text = initial_text.rstrip('\n') + '\n' |
662 content = gclient_utils.RunEditor(content, True) | 663 content = gclient_utils.RunEditor(initial_text, True) |
663 if not content: | 664 if not content: |
664 DieWithError('Running editor failed') | 665 DieWithError('Running editor failed') |
665 content = re.compile(r'^#.*$', re.MULTILINE).sub('', content).strip() | 666 content = re.compile(r'^#.*$', re.MULTILINE).sub('', content).strip() |
666 if not content: | 667 if not content: |
667 DieWithError('No CL description, aborting') | 668 DieWithError('No CL description, aborting') |
668 self.description = content.strip('\n') + '\n' | 669 self._ParseDescription(content) |
669 | 670 |
670 def ParseDescription(self): | 671 def _ParseDescription(self, description): |
671 """Updates the list of reviewers.""" | 672 """Updates the list of reviewers and subject from the description.""" |
| 673 if not description: |
| 674 self.description = description |
| 675 return |
| 676 |
| 677 self.description = description.strip('\n') + '\n' |
| 678 self.subject = description.split('\n', 1)[0] |
672 # Retrieves all reviewer lines | 679 # Retrieves all reviewer lines |
673 regexp = re.compile(r'^\s*(TBR|R)=(.+)$', re.MULTILINE) | 680 regexp = re.compile(r'^\s*(TBR|R)=(.+)$', re.MULTILINE) |
674 reviewers = ','.join( | 681 self.reviewers = ','.join( |
675 i.group(2).strip() for i in regexp.finditer(self.description)) | 682 i.group(2).strip() for i in regexp.finditer(self.description)) |
676 if reviewers: | |
677 self.reviewers = reviewers | |
678 | 683 |
679 def IsEmpty(self): | 684 def IsEmpty(self): |
680 return not self.description | 685 return not self.description |
681 | 686 |
682 | 687 |
683 def FindCodereviewSettingsFile(filename='codereview.settings'): | 688 def FindCodereviewSettingsFile(filename='codereview.settings'): |
684 """Finds the given file starting in the cwd and going up. | 689 """Finds the given file starting in the cwd and going up. |
685 | 690 |
686 Only looks up to the top of the repository unless an | 691 Only looks up to the top of the repository unless an |
687 'inherit-review-settings-ok' file exists in the root of the repository. | 692 'inherit-review-settings-ok' file exists in the root of the repository. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 env = os.environ.copy() | 918 env = os.environ.copy() |
914 if 'GIT_EXTERNAL_DIFF' in env: | 919 if 'GIT_EXTERNAL_DIFF' in env: |
915 del env['GIT_EXTERNAL_DIFF'] | 920 del env['GIT_EXTERNAL_DIFF'] |
916 subprocess2.call( | 921 subprocess2.call( |
917 ['git', 'diff', '--no-ext-diff', '--stat', '-M'] + args, env=env) | 922 ['git', 'diff', '--no-ext-diff', '--stat', '-M'] + args, env=env) |
918 | 923 |
919 upload_args = ['--assume_yes'] # Don't ask about untracked files. | 924 upload_args = ['--assume_yes'] # Don't ask about untracked files. |
920 upload_args.extend(['--server', cl.GetRietveldServer()]) | 925 upload_args.extend(['--server', cl.GetRietveldServer()]) |
921 if options.emulate_svn_auto_props: | 926 if options.emulate_svn_auto_props: |
922 upload_args.append('--emulate_svn_auto_props') | 927 upload_args.append('--emulate_svn_auto_props') |
| 928 if options.from_logs and not options.message: |
| 929 print 'Must set message for subject line if using desc_from_logs' |
| 930 return 1 |
923 | 931 |
924 change_desc = None | 932 change_desc = None |
925 | 933 |
926 if cl.GetIssue(): | 934 if cl.GetIssue(): |
927 if options.message: | 935 if options.message: |
928 upload_args.extend(['--message', options.message]) | 936 upload_args.extend(['--message', options.message]) |
929 upload_args.extend(['--issue', cl.GetIssue()]) | 937 upload_args.extend(['--issue', cl.GetIssue()]) |
930 print ("This branch is associated with issue %s. " | 938 print ("This branch is associated with issue %s. " |
931 "Adding patch to that issue." % cl.GetIssue()) | 939 "Adding patch to that issue." % cl.GetIssue()) |
932 else: | 940 else: |
933 message = options.message or CreateDescriptionFromLog(args) | 941 log_desc = CreateDescriptionFromLog(args) |
934 change_desc = ChangeDescription(message, options.reviewers) | 942 change_desc = ChangeDescription(options.message, log_desc, |
935 if not options.force: | 943 options.reviewers) |
936 change_desc.Prompt() | 944 if not options.from_logs: |
937 change_desc.ParseDescription() | 945 change_desc.Update() |
938 | 946 |
939 if change_desc.IsEmpty(): | 947 if change_desc.IsEmpty(): |
940 print "Description is empty; aborting." | 948 print "Description is empty; aborting." |
941 return 1 | 949 return 1 |
942 | 950 |
943 upload_args.extend(['--message', change_desc.description]) | 951 upload_args.extend(['--message', change_desc.subject]) |
| 952 upload_args.extend(['--description', change_desc.description]) |
944 if change_desc.reviewers: | 953 if change_desc.reviewers: |
945 upload_args.extend(['--reviewers', change_desc.reviewers]) | 954 upload_args.extend(['--reviewers', change_desc.reviewers]) |
946 if options.send_mail: | 955 if options.send_mail: |
947 if not change_desc.reviewers: | 956 if not change_desc.reviewers: |
948 DieWithError("Must specify reviewers to send email.") | 957 DieWithError("Must specify reviewers to send email.") |
949 upload_args.append('--send_mail') | 958 upload_args.append('--send_mail') |
950 cc = ','.join(filter(None, (cl.GetCCList(), options.cc))) | 959 cc = ','.join(filter(None, (cl.GetCCList(), options.cc))) |
951 if cc: | 960 if cc: |
952 upload_args.extend(['--cc', cc]) | 961 upload_args.extend(['--cc', cc]) |
953 | 962 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1428 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1420 | 1429 |
1421 # Not a known command. Default to help. | 1430 # Not a known command. Default to help. |
1422 GenUsage(parser, 'help') | 1431 GenUsage(parser, 'help') |
1423 return CMDhelp(parser, argv) | 1432 return CMDhelp(parser, argv) |
1424 | 1433 |
1425 | 1434 |
1426 if __name__ == '__main__': | 1435 if __name__ == '__main__': |
1427 fix_encoding.fix_encoding() | 1436 fix_encoding.fix_encoding() |
1428 sys.exit(main(sys.argv[1:])) | 1437 sys.exit(main(sys.argv[1:])) |
OLD | NEW |