| 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 json | 10 import json |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL', | 791 SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL', |
| 792 'tree-status-url', False) | 792 'tree-status-url', False) |
| 793 SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True) | 793 SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True) |
| 794 | 794 |
| 795 # TODO: configure a default branch to diff against, rather than this | 795 # TODO: configure a default branch to diff against, rather than this |
| 796 # svn-based hackery. | 796 # svn-based hackery. |
| 797 | 797 |
| 798 | 798 |
| 799 class ChangeDescription(object): | 799 class ChangeDescription(object): |
| 800 """Contains a parsed form of the change description.""" | 800 """Contains a parsed form of the change description.""" |
| 801 R_LINE = r'^\s*(TBR|R)\s*=\s*(.+)\s*$' | 801 R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$' |
| 802 | 802 |
| 803 def __init__(self, description): | 803 def __init__(self, description): |
| 804 self._description = (description or '').strip() | 804 self._description = (description or '').strip() |
| 805 | 805 |
| 806 @property | 806 @property |
| 807 def description(self): | 807 def description(self): |
| 808 return self._description | 808 return self._description |
| 809 | 809 |
| 810 def update_reviewers(self, reviewers): | 810 def update_reviewers(self, reviewers): |
| 811 """Rewrites the R=/TBR= line(s) as a single line.""" | 811 """Rewrites the R=/TBR= line(s) as a single line.""" |
| 812 assert isinstance(reviewers, list), reviewers | 812 assert isinstance(reviewers, list), reviewers |
| 813 if not reviewers: | 813 if not reviewers: |
| 814 return | 814 return |
| 815 regexp = re.compile(self.R_LINE, re.MULTILINE) | 815 regexp = re.compile(self.R_LINE, re.MULTILINE) |
| 816 matches = list(regexp.finditer(self._description)) | 816 matches = list(regexp.finditer(self._description)) |
| 817 is_tbr = any(m.group(1) == 'TBR' for m in matches) | 817 is_tbr = any(m.group(1) == 'TBR' for m in matches) |
| 818 if len(matches) > 1: | 818 if len(matches) > 1: |
| 819 # Erase all except the first one. | 819 # Erase all except the first one. |
| 820 for i in xrange(len(matches) - 1, 0, -1): | 820 for i in xrange(len(matches) - 1, 0, -1): |
| 821 self._description = ( | 821 self._description = ( |
| 822 self._description[:matches[i].start()] + | 822 self._description[:matches[i].start()] + |
| 823 self._description[matches[i].end()+1:]) | 823 self._description[matches[i].end():]) |
| 824 | 824 |
| 825 if is_tbr: | 825 if is_tbr: |
| 826 new_r_line = 'TBR=' + ', '.join(reviewers) | 826 new_r_line = 'TBR=' + ', '.join(reviewers) |
| 827 else: | 827 else: |
| 828 new_r_line = 'R=' + ', '.join(reviewers) | 828 new_r_line = 'R=' + ', '.join(reviewers) |
| 829 | 829 |
| 830 if matches: | 830 if matches: |
| 831 self._description = ( | 831 self._description = ( |
| 832 self._description[:matches[0].start()] + new_r_line + | 832 self._description[:matches[0].start()] + new_r_line + |
| 833 self._description[matches[0].end()+1:]) | 833 self._description[matches[0].end():]).strip() |
| 834 else: | 834 else: |
| 835 self.append_footer(new_r_line) | 835 self.append_footer(new_r_line) |
| 836 | 836 |
| 837 def prompt(self): | 837 def prompt(self): |
| 838 """Asks the user to update the description.""" | 838 """Asks the user to update the description.""" |
| 839 self._description = ( | 839 self._description = ( |
| 840 '# Enter a description of the change.\n' | 840 '# Enter a description of the change.\n' |
| 841 '# This will displayed on the codereview site.\n' | 841 '# This will displayed on the codereview site.\n' |
| 842 '# The first line will also be used as the subject of the review.\n' | 842 '# The first line will also be used as the subject of the review.\n' |
| 843 ) + self._description | 843 ) + self._description |
| (...skipping 18 matching lines...) Expand all Loading... |
| 862 else: | 862 else: |
| 863 last_line = self._description.rsplit('\n', 1)[1] | 863 last_line = self._description.rsplit('\n', 1)[1] |
| 864 if (not presubmit_support.Change.TAG_LINE_RE.match(last_line) or | 864 if (not presubmit_support.Change.TAG_LINE_RE.match(last_line) or |
| 865 not presubmit_support.Change.TAG_LINE_RE.match(line)): | 865 not presubmit_support.Change.TAG_LINE_RE.match(line)): |
| 866 self._description += '\n' | 866 self._description += '\n' |
| 867 self._description += '\n' + line | 867 self._description += '\n' + line |
| 868 | 868 |
| 869 def get_reviewers(self): | 869 def get_reviewers(self): |
| 870 """Retrieves the list of reviewers.""" | 870 """Retrieves the list of reviewers.""" |
| 871 regexp = re.compile(self.R_LINE, re.MULTILINE) | 871 regexp = re.compile(self.R_LINE, re.MULTILINE) |
| 872 reviewers = [i.group(2) for i in regexp.finditer(self._description)] | 872 reviewers = [i.group(2).strip() for i in regexp.finditer(self._description)] |
| 873 return cleanup_list(reviewers) | 873 return cleanup_list(reviewers) |
| 874 | 874 |
| 875 | 875 |
| 876 def FindCodereviewSettingsFile(filename='codereview.settings'): | 876 def FindCodereviewSettingsFile(filename='codereview.settings'): |
| 877 """Finds the given file starting in the cwd and going up. | 877 """Finds the given file starting in the cwd and going up. |
| 878 | 878 |
| 879 Only looks up to the top of the repository unless an | 879 Only looks up to the top of the repository unless an |
| 880 'inherit-review-settings-ok' file exists in the root of the repository. | 880 'inherit-review-settings-ok' file exists in the root of the repository. |
| 881 """ | 881 """ |
| 882 inherit_ok_file = 'inherit-review-settings-ok' | 882 inherit_ok_file = 'inherit-review-settings-ok' |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1968 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1969 | 1969 |
| 1970 # Not a known command. Default to help. | 1970 # Not a known command. Default to help. |
| 1971 GenUsage(parser, 'help') | 1971 GenUsage(parser, 'help') |
| 1972 return CMDhelp(parser, argv) | 1972 return CMDhelp(parser, argv) |
| 1973 | 1973 |
| 1974 | 1974 |
| 1975 if __name__ == '__main__': | 1975 if __name__ == '__main__': |
| 1976 fix_encoding.fix_encoding() | 1976 fix_encoding.fix_encoding() |
| 1977 sys.exit(main(sys.argv[1:])) | 1977 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |