Skip to content

Commit

Permalink
checkpatch: Print file line numbers
Browse files Browse the repository at this point in the history
The line numbers being printed were the line numbers for the patchfile.
This is sometimes okay to fix simple things (trailing or leading
whitespace, missing signoffs, etc).  But more complicated fixes, or
those fixes which require a bit more care, aren't helped by this.  So,
we use the implied file line number.

This can be useful with future work to 'mock' apply and build a real
contextual scanner for checking multi-line changes.

Signed-off-by: Aaron Conole <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
apconole authored and blp committed Nov 29, 2016
1 parent e3ecc9d commit 4d7f5e5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions utilities/checkpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def print_warning(message, lineno=None):


__regex_added_line = re.compile(r'^\+{1,2}[^\+][\w\W]*')
__regex_subtracted_line = re.compile(r'^\-{1,2}[^\-][\w\W]*')
__regex_leading_with_whitespace_at_all = re.compile(r'^\s+')
__regex_leading_with_spaces = re.compile(r'^ +[\S]+')
__regex_trailing_whitespace = re.compile(r'[^\S]+$')
Expand All @@ -79,6 +80,10 @@ def print_warning(message, lineno=None):
'.py']


def is_subtracted_line(line):
"""Returns TRUE if the line in question has been removed."""
return __regex_subtracted_line.search(line) is not None

def is_added_line(line):
"""Returns TRUE if the line in question is an added line.
"""
Expand Down Expand Up @@ -150,6 +155,8 @@ def ovs_checkpatch_parse(text):
previous_file = ''
scissors = re.compile(r'^[\w]*---[\w]*')
hunks = re.compile('^(---|\+\+\+) (\S+)')
hunk_differences = re.compile(
r'^@@ ([0-9-+]+),([0-9-+]+) ([0-9-+]+),([0-9-+]+) @@')
is_signature = re.compile(r'((\s*Signed-off-by: )(.*))$',
re.I | re.M | re.S)
is_co_author = re.compile(r'(\s*(Co-authored-by: )(.*))$',
Expand Down Expand Up @@ -199,6 +206,14 @@ def ovs_checkpatch_parse(text):
current_file = newfile.group(2)
print_file_name = current_file
continue
reset_line_number = hunk_differences.match(line)
if reset_line_number:
lineno = int(reset_line_number.group(3))
if lineno < 0:
lineno = -1 * lineno
lineno -= 1
if is_subtracted_line(line):
lineno -= 1
if not is_added_line(line):
continue
# Skip files which have /datapath in them, since they are
Expand Down

0 comments on commit 4d7f5e5

Please sign in to comment.