Merge branch 'misc.namei' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-2.6-microblaze.git] / scripts / checkpatch.pl
index 461d422..c27d231 100755 (executable)
@@ -501,7 +501,7 @@ our $Binary = qr{(?i)0b[01]+$Int_type?};
 our $Hex       = qr{(?i)0x[0-9a-f]+$Int_type?};
 our $Int       = qr{[0-9]+$Int_type?};
 our $Octal     = qr{0[0-7]+$Int_type?};
-our $String    = qr{"[X\t]*"};
+our $String    = qr{(?:\b[Lu])?"[X\t]*"};
 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
@@ -1181,7 +1181,8 @@ sub git_commit_info {
 #                  git log --format='%H %s' -1 $line |
 #                  echo "commit $(cut -c 1-12,41-)"
 #              done
-       } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) {
+       } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./ ||
+                $lines[0] =~ /^fatal: bad object $commit/) {
                $id = undef;
        } else {
                $id = substr($lines[0], 0, 12);
@@ -2587,6 +2588,8 @@ sub process {
        my $reported_maintainer_file = 0;
        my $non_utf8_charset = 0;
 
+       my $last_git_commit_id_linenr = -1;
+
        my $last_blank_line = 0;
        my $last_coalesced_string_linenr = -1;
 
@@ -2909,10 +2912,10 @@ sub process {
                                        my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);
                                        my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author);
 
-                                       if ($email_address eq $author_address && $email_name eq $author_name) {
+                                       if (lc $email_address eq lc $author_address && $email_name eq $author_name) {
                                                $author_sob = $ctx;
                                                $authorsignoff = 2;
-                                       } elsif ($email_address eq $author_address) {
+                                       } elsif (lc $email_address eq lc $author_address) {
                                                $author_sob = $ctx;
                                                $authorsignoff = 3;
                                        } elsif ($email_name eq $author_name) {
@@ -3170,10 +3173,20 @@ sub process {
                }
 
 # Check for git id commit length and improperly formed commit descriptions
-               if ($in_commit_log && !$commit_log_possible_stack_dump &&
+# A correctly formed commit description is:
+#    commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
+# with the commit subject '("' prefix and '")' suffix
+# This is a fairly compilicated block as it tests for what appears to be
+# bare SHA-1 hash with  minimum length of 5.  It also avoids several types of
+# possible SHA-1 matches.
+# A commit match can span multiple lines so this block attempts to find a
+# complete typical commit on a maximum of 3 lines
+               if ($perl_version_ok &&
+                   $in_commit_log && !$commit_log_possible_stack_dump &&
                    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
                    $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
-                   ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+                   (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+                     ($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||
                     ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
                      $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
                      $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
@@ -3183,49 +3196,56 @@ sub process {
                        my $long = 0;
                        my $case = 1;
                        my $space = 1;
-                       my $hasdesc = 0;
-                       my $hasparens = 0;
                        my $id = '0123456789ab';
                        my $orig_desc = "commit description";
                        my $description = "";
+                       my $herectx = $herecurr;
+                       my $has_parens = 0;
+                       my $has_quotes = 0;
+
+                       my $input = $line;
+                       if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
+                               for (my $n = 0; $n < 2; $n++) {
+                                       if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
+                                               $orig_desc = $1;
+                                               $has_parens = 1;
+                                               # Always strip leading/trailing parens then double quotes if existing
+                                               $orig_desc = substr($orig_desc, 1, -1);
+                                               if ($orig_desc =~ /^".*"$/) {
+                                                       $orig_desc = substr($orig_desc, 1, -1);
+                                                       $has_quotes = 1;
+                                               }
+                                               last;
+                                       }
+                                       last if ($#lines < $linenr + $n);
+                                       $input .= " " . trim($rawlines[$linenr + $n]);
+                                       $herectx .= "$rawlines[$linenr + $n]\n";
+                               }
+                               $herectx = $herecurr if (!$has_parens);
+                       }
 
-                       if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
+                       if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
                                $init_char = $1;
                                $orig_commit = lc($2);
-                       } elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
+                               $short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
+                               $long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
+                               $space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
+                               $case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
+                       } elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
                                $orig_commit = lc($1);
                        }
 
-                       $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
-                       $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
-                       $space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
-                       $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
-                       if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
-                               $orig_desc = $1;
-                               $hasparens = 1;
-                       } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
-                                defined $rawlines[$linenr] &&
-                                $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
-                               $orig_desc = $1;
-                               $hasparens = 1;
-                       } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
-                                defined $rawlines[$linenr] &&
-                                $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
-                               $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
-                               $orig_desc = $1;
-                               $rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
-                               $orig_desc .= " " . $1;
-                               $hasparens = 1;
-                       }
-
                        ($id, $description) = git_commit_info($orig_commit,
                                                              $id, $orig_desc);
 
                        if (defined($id) &&
-                          ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
+                           ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) &&
+                           $last_git_commit_id_linenr != $linenr - 1) {
                                ERROR("GIT_COMMIT_ID",
-                                     "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
+                                     "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);
                        }
+                       #don't report the next line if this line ends in commit and the sha1 hash is the next line
+                       $last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
                }
 
 # Check for added, moved or deleted files
@@ -6132,7 +6152,8 @@ sub process {
                }
 
 # concatenated string without spaces between elements
-               if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
+               if ($line =~ /$String[A-Z_]/ ||
+                   ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
                        if (CHK("CONCATENATED_STRING",
                                "Concatenated strings should use spaces between elements\n" . $herecurr) &&
                            $fix) {
@@ -6145,7 +6166,7 @@ sub process {
                }
 
 # uncoalesced string fragments
-               if ($line =~ /$String\s*"/) {
+               if ($line =~ /$String\s*[Lu]?"/) {
                        if (WARN("STRING_FRAGMENTS",
                                 "Consecutive strings are generally better as a single string\n" . $herecurr) &&
                            $fix) {