OSDN Git Service

checkpatch: improve the embedded function name test for patch contexts
authorJoe Perches <joe@perches.com>
Mon, 8 May 2017 22:56:02 +0000 (15:56 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 May 2017 00:15:11 +0000 (17:15 -0700)
The current test works only for a single patch context as it is done in
the foreach ($rawlines) loop that precedes the loop where the actual
$context_function variable is used.

Move the set of $context_function into the foreach (@lines) loop where
it is useful for each patch context.

Link: http://lkml.kernel.org/r/6c675a31c74fbfad4fc45b9f462303d60ca2a283.1493486091.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index 65bb500..3374040 100755 (executable)
@@ -2213,8 +2213,7 @@ sub process {
                        }
                        #next;
                }
-               if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
-                       my $context = $4;
+               if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
                        $realline=$1-1;
                        if (defined $2) {
                                $realcnt=$3+1;
@@ -2223,12 +2222,6 @@ sub process {
                        }
                        $in_comment = 0;
 
-                       if ($context =~ /\b(\w+)\s*\(/) {
-                               $context_function = $1;
-                       } else {
-                               undef $context_function;
-                       }
-
                        # Guestimate if this is a continuing comment.  Run
                        # the context looking for a comment "edge".  If this
                        # edge is a close comment then we must be in a comment
@@ -2299,7 +2292,8 @@ sub process {
 
 #extract the line range in the file after the patch is applied
                if (!$in_commit_log &&
-                   $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
+                   $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
+                       my $context = $4;
                        $is_patch = 1;
                        $first_line = $linenr + 1;
                        $realline=$1-1;
@@ -2315,6 +2309,11 @@ sub process {
                        %suppress_whiletrailers = ();
                        %suppress_export = ();
                        $suppress_statement = 0;
+                       if ($context =~ /\b(\w+)\s*\(/) {
+                               $context_function = $1;
+                       } else {
+                               undef $context_function;
+                       }
                        next;
 
 # track the line number as we move through the hunk, note that