Commit dfa05c28 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: remove email address comment from email address comparisons

About 2% of the last 100K commits have email addresses that include an
RFC2822 compliant comment like:

	Peter Zijlstra (Intel) <peterz@infradead.org>

checkpatch currently does a comparison of the complete name and address to
the submitted author to determine if the author has signed-off and emits a
warning if the exact email names and addresses do not match.

Unfortunately, the author email address can be written without the comment
like:

	Peter Zijlstra <peterz@infradead.org>

Add logic to compare the comment stripped email addresses to avoid this
warning.
Reported-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: http://lkml.kernel.org/r/ebaa2f7c8f94e25520981945cddcc1982e70e072.camel@perches.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8306b057
...@@ -1118,6 +1118,7 @@ sub parse_email { ...@@ -1118,6 +1118,7 @@ sub parse_email {
my ($formatted_email) = @_; my ($formatted_email) = @_;
my $name = ""; my $name = "";
my $name_comment = "";
my $address = ""; my $address = "";
my $comment = ""; my $comment = "";
...@@ -1150,6 +1151,10 @@ sub parse_email { ...@@ -1150,6 +1151,10 @@ sub parse_email {
$name = trim($name); $name = trim($name);
$name =~ s/^\"|\"$//g; $name =~ s/^\"|\"$//g;
$name =~ s/(\s*\([^\)]+\))\s*//;
if (defined($1)) {
$name_comment = trim($1);
}
$address = trim($address); $address = trim($address);
$address =~ s/^\<|\>$//g; $address =~ s/^\<|\>$//g;
...@@ -1158,7 +1163,7 @@ sub parse_email { ...@@ -1158,7 +1163,7 @@ sub parse_email {
$name = "\"$name\""; $name = "\"$name\"";
} }
return ($name, $address, $comment); return ($name, $name_comment, $address, $comment);
} }
sub format_email { sub format_email {
...@@ -1184,6 +1189,23 @@ sub format_email { ...@@ -1184,6 +1189,23 @@ sub format_email {
return $formatted_email; return $formatted_email;
} }
sub reformat_email {
my ($email) = @_;
my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
return format_email($email_name, $email_address);
}
sub same_email_addresses {
my ($email1, $email2) = @_;
my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1);
my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2);
return $email1_name eq $email2_name &&
$email1_address eq $email2_address;
}
sub which { sub which {
my ($bin) = @_; my ($bin) = @_;
...@@ -2604,17 +2626,16 @@ sub process { ...@@ -2604,17 +2626,16 @@ sub process {
$author = $1; $author = $1;
$author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i); $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
$author =~ s/"//g; $author =~ s/"//g;
$author = reformat_email($author);
} }
# Check the patch for a signoff: # Check the patch for a signoff:
if ($line =~ /^\s*signed-off-by:/i) { if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
$signoff++; $signoff++;
$in_commit_log = 0; $in_commit_log = 0;
if ($author ne '') { if ($author ne '') {
my $l = $line; if (same_email_addresses($1, $author)) {
$l =~ s/"//g; $authorsignoff = 1;
if ($l =~ /^\s*signed-off-by:\s*\Q$author\E/i) {
$authorsignoff = 1;
} }
} }
} }
...@@ -2664,7 +2685,7 @@ sub process { ...@@ -2664,7 +2685,7 @@ sub process {
} }
} }
my ($email_name, $email_address, $comment) = parse_email($email); my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
my $suggested_email = format_email(($email_name, $email_address)); my $suggested_email = format_email(($email_name, $email_address));
if ($suggested_email eq "") { if ($suggested_email eq "") {
ERROR("BAD_SIGN_OFF", ERROR("BAD_SIGN_OFF",
...@@ -2675,9 +2696,7 @@ sub process { ...@@ -2675,9 +2696,7 @@ sub process {
$dequoted =~ s/" </ </; $dequoted =~ s/" </ </;
# Don't force email to have quotes # Don't force email to have quotes
# Allow just an angle bracketed address # Allow just an angle bracketed address
if ("$dequoted$comment" ne $email && if (!same_email_addresses($email, $suggested_email)) {
"<$email_address>$comment" ne $email &&
"$suggested_email$comment" ne $email) {
WARN("BAD_SIGN_OFF", WARN("BAD_SIGN_OFF",
"email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr); "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment