Chromium Code Reviews| Index: presubmit_support.py |
| diff --git a/presubmit_support.py b/presubmit_support.py |
| index 79bc306bdcb306be12afca6929d25e0b548e4177..0f0cf8938791d4c9b207586c77738e9e940b6096 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 |
| + # file. This relies on the git diff output describing each changed code |
|
M-A Ruel
2011/02/09 14:16:10
the scm diff output
vb
2011/02/09 18:24:41
Done.
|
| + # 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.split('\n'): |
|
M-A Ruel
2011/02/09 14:16:10
for line in self.GenerateScmDiff().splitlines():
vb
2011/02/09 18:24:41
Done.
|
| + m = re.match('^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+ @@', line) |
|
M-A Ruel
2011/02/09 14:16:10
m = re.match(r'^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+
vb
2011/02/09 18:24:41
Done.
|
| + if m: |
| + line_num = int(m.groups(1)[0]) |
| + continue |
| + if re.search('^\+[^\+]', line): |
|
M-A Ruel
2011/02/09 14:16:10
if re.search(r'^\+[^\+]', line):
vb
2011/02/09 18:24:41
Done.
|
| + new_lines.append((line_num, line[1:])) |
| + if not re.search('^\-[^\-]', line): |
|
M-A Ruel
2011/02/09 14:16:10
if not re.search(r'^\-[^\-]', line):
vb
2011/02/09 18:24:41
Done.
|
| + 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. |