Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: git_cl.py

Issue 23072039: Fix R= line rewriter to handle TBRs well. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | tests/git_cl_test.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$' 851 R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$'
852 852
853 def __init__(self, description): 853 def __init__(self, description):
854 self._description = (description or '').strip() 854 self._description = (description or '').strip()
855 855
856 @property 856 @property
857 def description(self): 857 def description(self):
858 return self._description 858 return self._description
859 859
860 def update_reviewers(self, reviewers): 860 def update_reviewers(self, reviewers):
861 """Rewrites the R=/TBR= line(s) as a single line.""" 861 """Rewrites the R=/TBR= line(s) as a single line each."""
862 assert isinstance(reviewers, list), reviewers 862 assert isinstance(reviewers, list), reviewers
863 if not reviewers: 863 if not reviewers:
864 return 864 return
865 regexp = re.compile(self.R_LINE, re.MULTILINE) 865 regexp = re.compile(self.R_LINE, re.MULTILINE)
866 matches = list(regexp.finditer(self._description)) 866 matches = list(regexp.finditer(self._description))
867 is_tbr = any(m.group(1) == 'TBR' for m in matches) 867 r_names = []
868 tbr_names = []
869 for line in matches:
870 is_tbr = line.group(1) == 'TBR'
871 people = cleanup_list([line.group(2).strip()])
872 if is_tbr:
873 tbr_names += people
874 else:
875 r_names += people
868 if len(matches) > 1: 876 if len(matches) > 1:
869 # Erase all except the first one. 877 # Erase all except the first one.
870 for i in xrange(len(matches) - 1, 0, -1): 878 for i in xrange(len(matches) - 1, 0, -1):
871 self._description = ( 879 self._description = (
872 self._description[:matches[i].start()] + 880 self._description[:matches[i].start()] +
873 self._description[matches[i].end():]) 881 self._description[matches[i].end():])
882 # Copy the names from the description into the official list.
883 for name in r_names:
884 if name not in reviewers:
885 reviewers.append(name)
874 886
875 if is_tbr: 887 new_r_line = 'R=' + ', '.join(reviewers)
M-A Ruel 2013/08/23 15:22:53 I'd also skip it unless "if reviewers:"
agable 2013/08/23 18:43:00 I ended up refactoring most of the ChangeDescripti
876 new_r_line = 'TBR=' + ', '.join(reviewers) 888 if tbr_names:
877 else: 889 new_r_line += '\nTBR=' + ', '.join(tbr_names)
878 new_r_line = 'R=' + ', '.join(reviewers)
879 890
880 if matches: 891 if matches:
881 self._description = ( 892 self._description = (
882 self._description[:matches[0].start()] + new_r_line + 893 self._description[:matches[0].start()] + new_r_line +
883 self._description[matches[0].end():]).strip() 894 self._description[matches[0].end():]).strip()
884 else: 895 else:
885 self.append_footer(new_r_line) 896 self.append_footer(new_r_line)
886 897
887 def prompt(self): 898 def prompt(self):
888 """Asks the user to update the description.""" 899 """Asks the user to update the description."""
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2208 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2198 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2209 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2199 2210
2200 2211
2201 if __name__ == '__main__': 2212 if __name__ == '__main__':
2202 # These affect sys.stdout so do it outside of main() to simplify mocks in 2213 # These affect sys.stdout so do it outside of main() to simplify mocks in
2203 # unit testing. 2214 # unit testing.
2204 fix_encoding.fix_encoding() 2215 fix_encoding.fix_encoding()
2205 colorama.init() 2216 colorama.init()
2206 sys.exit(main(sys.argv[1:])) 2217 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | tests/git_cl_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698