Chromium Code Reviews| Index: presubmit_support.py |
| diff --git a/presubmit_support.py b/presubmit_support.py |
| index 049438d7500eef415ab988178adf54fe3e9ca22d..3365cd089ace959c6ad2edd42a493db8210852ca 100755 |
| --- a/presubmit_support.py |
| +++ b/presubmit_support.py |
| @@ -86,11 +86,9 @@ def PromptYesNo(input_stream, output_stream, prompt): |
| def _RightHandSideLinesImpl(affected_files): |
| """Implements RightHandSideLines for InputApi and GclChange.""" |
| for af in affected_files: |
| - lines = af.NewContents() |
| - line_number = 0 |
| + lines = af.ChangedContents() |
| for line in lines: |
| - line_number += 1 |
| - yield (af, line_number, line) |
| + yield (af, line[0], line[1]) |
| class OutputApi(object): |
| @@ -481,6 +479,27 @@ class AffectedFile(object): |
| """ |
| raise NotImplementedError() # Implement if/when needed. |
| + def ChangedContents(self): |
| + # Return a list of tuples (line number, line text) of all new lines in the |
|
M-A Ruel
2011/02/09 18:30:26
I think it should be a docstring.
"""Returns a li
vb
2011/02/09 18:54:11
Done.
|
| + # file. This relies on the scm diff output describing each changed code |
| + # section with a line of the form |
| + # |
| + # ^@@ <old line num>,<old size> <new line num>,<new size> @@$ |
| + # |
| + new_lines = [] |
| + line_num = 0 |
| + diff_text = self.GenerateScmDiff() |
| + for line in diff_text.splitlines(): |
|
M-A Ruel
2011/02/09 18:30:26
You didn't merge lines 491 and 492. You prefer to
vb
2011/02/09 18:54:11
good point, it was a leftover of previous code, no
|
| + m = re.match(r'^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+ @@', line) |
| + if m: |
| + line_num = int(m.groups(1)[0]) |
| + continue |
| + if re.search(r'^\+[^\+]', line): |
|
M-A Ruel
2011/02/09 18:30:26
Actually, this regexp is wrong:
what if the line
vb
2011/02/09 18:54:11
Yes, a good catch. Did away with regexp here, I th
|
| + new_lines.append((line_num, line[1:])) |
| + if not re.search(r'^\-[^\-]', line): |
| + line_num += 1 |
| + return new_lines |
| + |
| def __str__(self): |
| return self.LocalPath() |
| @@ -532,6 +551,8 @@ class SvnAffectedFile(AffectedFile): |
| self._is_text_file = (not mime_type or mime_type.startswith('text/')) |
| return self._is_text_file |
| + def GenerateScmDiff(self): |
| + return scm.SVN.GenerateDiff(self.AbsoluteLocalPath()) |
| class GitAffectedFile(AffectedFile): |
| """Representation of a file in a change out of a git checkout.""" |
| @@ -577,6 +598,10 @@ class GitAffectedFile(AffectedFile): |
| self._is_text_file = os.path.isfile(self.AbsoluteLocalPath()) |
| return self._is_text_file |
| + def GenerateScmDiff(self): |
| + return scm.GIT.GenerateDiff( |
| + os.path.dirname(self.AbsoluteLocalPath()), |
| + files=[os.path.basename(self.AbsoluteLocalPath()),]) |
| class Change(object): |
| """Describe a change. |