diff options
| author | Joe Perches <joe@perches.com> | 2011-07-25 20:13:23 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-25 23:57:16 -0400 |
| commit | 2011247550c1b903a9ecd68f6eb3e9e7b7b07f52 (patch) | |
| tree | afd2ca6683f7225d29df77fb4c19b81211c05a57 /scripts | |
| parent | 165e72a6c374ed03c57d03c88406d32745e1add2 (diff) | |
checkpatch: validate signature styles and To: and Cc: lines
Signatures have many forms and can sometimes cause problems if not in the
correct format when using git send-email or quilt.
Try to verify the signature tags and email addresses to use the generally
accepted "Signed-off-by: Full Name <email@domain.tld>" form.
Original idea by Anish Kumar <anish198519851985@gmail.com>
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Anish Kumar <anish198519851985@gmail.com>
Cc: Nick Bowler <nbowler@elliptictech.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 123 |
1 files changed, 115 insertions, 8 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 63cca81b1105..b14f830cb0fa 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -217,6 +217,16 @@ our $logFunctions = qr{(?x: | |||
| 217 | MODULE_[A-Z_]+ | 217 | MODULE_[A-Z_]+ |
| 218 | )}; | 218 | )}; |
| 219 | 219 | ||
| 220 | our $signature_tags = qr{(?xi: | ||
| 221 | Signed-off-by:| | ||
| 222 | Acked-by:| | ||
| 223 | Tested-by:| | ||
| 224 | Reviewed-by:| | ||
| 225 | Reported-by:| | ||
| 226 | To:| | ||
| 227 | Cc: | ||
| 228 | )}; | ||
| 229 | |||
| 220 | our @typeList = ( | 230 | our @typeList = ( |
| 221 | qr{void}, | 231 | qr{void}, |
| 222 | qr{(?:unsigned\s+)?char}, | 232 | qr{(?:unsigned\s+)?char}, |
| @@ -356,6 +366,76 @@ sub top_of_kernel_tree { | |||
| 356 | return 1; | 366 | return 1; |
| 357 | } | 367 | } |
| 358 | 368 | ||
| 369 | sub parse_email { | ||
| 370 | my ($formatted_email) = @_; | ||
| 371 | |||
| 372 | my $name = ""; | ||
| 373 | my $address = ""; | ||
| 374 | my $comment = ""; | ||
| 375 | |||
| 376 | if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) { | ||
| 377 | $name = $1; | ||
| 378 | $address = $2; | ||
| 379 | $comment = $3 if defined $3; | ||
| 380 | } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) { | ||
| 381 | $address = $1; | ||
| 382 | $comment = $2 if defined $2; | ||
| 383 | } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) { | ||
| 384 | $address = $1; | ||
| 385 | $comment = $2 if defined $2; | ||
| 386 | $formatted_email =~ s/$address.*$//; | ||
| 387 | $name = $formatted_email; | ||
| 388 | $name =~ s/^\s+|\s+$//g; | ||
| 389 | $name =~ s/^\"|\"$//g; | ||
| 390 | # If there's a name left after stripping spaces and | ||
| 391 | # leading quotes, and the address doesn't have both | ||
| 392 | # leading and trailing angle brackets, the address | ||
| 393 | # is invalid. ie: | ||
| 394 | # "joe smith joe@smith.com" bad | ||
| 395 | # "joe smith <joe@smith.com" bad | ||
| 396 | if ($name ne "" && $address !~ /^<[^>]+>$/) { | ||
| 397 | $name = ""; | ||
| 398 | $address = ""; | ||
| 399 | $comment = ""; | ||
| 400 | } | ||
| 401 | } | ||
| 402 | |||
| 403 | $name =~ s/^\s+|\s+$//g; | ||
| 404 | $name =~ s/^\"|\"$//g; | ||
| 405 | $address =~ s/^\s+|\s+$//g; | ||
| 406 | $address =~ s/^\<|\>$//g; | ||
| 407 | |||
| 408 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars | ||
| 409 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes | ||
| 410 | $name = "\"$name\""; | ||
| 411 | } | ||
| 412 | |||
| 413 | return ($name, $address, $comment); | ||
| 414 | } | ||
| 415 | |||
| 416 | sub format_email { | ||
| 417 | my ($name, $address) = @_; | ||
| 418 | |||
| 419 | my $formatted_email; | ||
| 420 | |||
| 421 | $name =~ s/^\s+|\s+$//g; | ||
| 422 | $name =~ s/^\"|\"$//g; | ||
| 423 | $address =~ s/^\s+|\s+$//g; | ||
| 424 | |||
| 425 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars | ||
| 426 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes | ||
| 427 | $name = "\"$name\""; | ||
| 428 | } | ||
| 429 | |||
| 430 | if ("$name" eq "") { | ||
| 431 | $formatted_email = "$address"; | ||
| 432 | } else { | ||
| 433 | $formatted_email = "$name <$address>"; | ||
| 434 | } | ||
| 435 | |||
| 436 | return $formatted_email; | ||
| 437 | } | ||
| 438 | |||
| 359 | sub expand_tabs { | 439 | sub expand_tabs { |
| 360 | my ($str) = @_; | 440 | my ($str) = @_; |
| 361 | 441 | ||
| @@ -1380,17 +1460,44 @@ sub process { | |||
| 1380 | } | 1460 | } |
| 1381 | } | 1461 | } |
| 1382 | 1462 | ||
| 1383 | #check the patch for a signoff: | 1463 | # Check the patch for a signoff: |
| 1384 | if ($line =~ /^\s*signed-off-by:/i) { | 1464 | if ($line =~ /^\s*signed-off-by:/i) { |
| 1385 | # This is a signoff, if ugly, so do not double report. | ||
| 1386 | $signoff++; | 1465 | $signoff++; |
| 1387 | if (!($line =~ /^\s*Signed-off-by:/)) { | 1466 | } |
| 1388 | WARN("Signed-off-by: is the preferred form\n" . | 1467 | |
| 1389 | $herecurr); | 1468 | # Check signature styles |
| 1469 | if ($line =~ /^(\s*)($signature_tags)(\s*)(.*)/) { | ||
| 1470 | my $space_before = $1; | ||
| 1471 | my $sign_off = $2; | ||
| 1472 | my $space_after = $3; | ||
| 1473 | my $email = $4; | ||
| 1474 | my $ucfirst_sign_off = ucfirst(lc($sign_off)); | ||
| 1475 | |||
| 1476 | if (defined $space_before && $space_before ne "") { | ||
| 1477 | WARN("Do not use whitespace before $ucfirst_sign_off\n" . $herecurr); | ||
| 1390 | } | 1478 | } |
| 1391 | if ($line =~ /^\s*signed-off-by:\S/i) { | 1479 | if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { |
| 1392 | WARN("space required after Signed-off-by:\n" . | 1480 | WARN("'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr); |
| 1393 | $herecurr); | 1481 | } |
| 1482 | if (!defined $space_after || $space_after ne " ") { | ||
| 1483 | WARN("Use a single space after $ucfirst_sign_off\n" . $herecurr); | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | my ($email_name, $email_address, $comment) = parse_email($email); | ||
| 1487 | my $suggested_email = format_email(($email_name, $email_address)); | ||
| 1488 | if ($suggested_email eq "") { | ||
| 1489 | ERROR("Unrecognized email address: '$email'\n" . $herecurr); | ||
| 1490 | } else { | ||
| 1491 | my $dequoted = $suggested_email; | ||
| 1492 | $dequoted =~ s/^"//; | ||
| 1493 | $dequoted =~ s/" </ </; | ||
| 1494 | # Don't force email to have quotes | ||
| 1495 | # Allow just an angle bracketed address | ||
| 1496 | if ("$dequoted$comment" ne $email && | ||
| 1497 | "<$email_address>$comment" ne $email && | ||
| 1498 | "$suggested_email$comment" ne $email) { | ||
| 1499 | WARN("email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr); | ||
| 1500 | } | ||
| 1394 | } | 1501 | } |
| 1395 | } | 1502 | } |
| 1396 | 1503 | ||
