Skip to content

Commit dfa05c2

Browse files
JoePerchestorvalds
authored andcommitted
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: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: http://lkml.kernel.org/r/ebaa2f7c8f94e25520981945cddcc1982e70e072.camel@perches.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8306b05 commit dfa05c2

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ sub parse_email {
11181118
my ($formatted_email) = @_;
11191119

11201120
my $name = "";
1121+
my $name_comment = "";
11211122
my $address = "";
11221123
my $comment = "";
11231124

@@ -1150,6 +1151,10 @@ sub parse_email {
11501151

11511152
$name = trim($name);
11521153
$name =~ s/^\"|\"$//g;
1154+
$name =~ s/(\s*\([^\)]+\))\s*//;
1155+
if (defined($1)) {
1156+
$name_comment = trim($1);
1157+
}
11531158
$address = trim($address);
11541159
$address =~ s/^\<|\>$//g;
11551160

@@ -1158,7 +1163,7 @@ sub parse_email {
11581163
$name = "\"$name\"";
11591164
}
11601165

1161-
return ($name, $address, $comment);
1166+
return ($name, $name_comment, $address, $comment);
11621167
}
11631168

11641169
sub format_email {
@@ -1184,6 +1189,23 @@ sub format_email {
11841189
return $formatted_email;
11851190
}
11861191

1192+
sub reformat_email {
1193+
my ($email) = @_;
1194+
1195+
my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
1196+
return format_email($email_name, $email_address);
1197+
}
1198+
1199+
sub same_email_addresses {
1200+
my ($email1, $email2) = @_;
1201+
1202+
my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1);
1203+
my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2);
1204+
1205+
return $email1_name eq $email2_name &&
1206+
$email1_address eq $email2_address;
1207+
}
1208+
11871209
sub which {
11881210
my ($bin) = @_;
11891211

@@ -2604,17 +2626,16 @@ sub process {
26042626
$author = $1;
26052627
$author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
26062628
$author =~ s/"//g;
2629+
$author = reformat_email($author);
26072630
}
26082631

26092632
# Check the patch for a signoff:
2610-
if ($line =~ /^\s*signed-off-by:/i) {
2633+
if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
26112634
$signoff++;
26122635
$in_commit_log = 0;
26132636
if ($author ne '') {
2614-
my $l = $line;
2615-
$l =~ s/"//g;
2616-
if ($l =~ /^\s*signed-off-by:\s*\Q$author\E/i) {
2617-
$authorsignoff = 1;
2637+
if (same_email_addresses($1, $author)) {
2638+
$authorsignoff = 1;
26182639
}
26192640
}
26202641
}
@@ -2664,7 +2685,7 @@ sub process {
26642685
}
26652686
}
26662687

2667-
my ($email_name, $email_address, $comment) = parse_email($email);
2688+
my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
26682689
my $suggested_email = format_email(($email_name, $email_address));
26692690
if ($suggested_email eq "") {
26702691
ERROR("BAD_SIGN_OFF",
@@ -2675,9 +2696,7 @@ sub process {
26752696
$dequoted =~ s/" </ </;
26762697
# Don't force email to have quotes
26772698
# Allow just an angle bracketed address
2678-
if ("$dequoted$comment" ne $email &&
2679-
"<$email_address>$comment" ne $email &&
2680-
"$suggested_email$comment" ne $email) {
2699+
if (!same_email_addresses($email, $suggested_email)) {
26812700
WARN("BAD_SIGN_OFF",
26822701
"email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
26832702
}

0 commit comments

Comments
 (0)