Fix a crash when a brand new file is added.
Checkstyle.py was not handling additions of new files resulting in
a crash. For new files git.modified_lines() returns None. Added code
handles that case.
Bug: 25852971
Change-Id: I91e2b8c92581ec9e89bcbbcd2d274f56c791f3a9
(cherry picked from commit 5b87dbad0c)
This commit is contained in:
@@ -106,9 +106,9 @@ def _ParseAndFilterOutput(stdout, sha, last_commit_modified_files):
|
|||||||
file_name = os.path.relpath(file_name)
|
file_name = os.path.relpath(file_name)
|
||||||
errors = file_element.getElementsByTagName('error')
|
errors = file_element.getElementsByTagName('error')
|
||||||
for error in errors:
|
for error in errors:
|
||||||
line = error.attributes['line'].value
|
line = int(error.attributes['line'].value)
|
||||||
if last_commit_modified_files and int(line) not in modified_lines:
|
rule = error.attributes['source'].value
|
||||||
if error.attributes['source'].value not in FORCED_RULES:
|
if last_commit_modified_files and _ShouldSkip(modified_lines, line, rule):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
column = ''
|
column = ''
|
||||||
@@ -125,6 +125,12 @@ def _ParseAndFilterOutput(stdout, sha, last_commit_modified_files):
|
|||||||
return (result_errors, result_warnings)
|
return (result_errors, result_warnings)
|
||||||
|
|
||||||
|
|
||||||
|
# Returns whether an error on a given line should be skipped
|
||||||
|
# based on the modified_lines list and the rule.
|
||||||
|
def _ShouldSkip(modified_lines, line, rule):
|
||||||
|
return modified_lines and line not in modified_lines and rule not in FORCED_RULES
|
||||||
|
|
||||||
|
|
||||||
def _GetModifiedFiles():
|
def _GetModifiedFiles():
|
||||||
root = git.repository_root()
|
root = git.repository_root()
|
||||||
sha = git.last_commit()
|
sha = git.last_commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user