Get maintainer script cleanups
cover Get maintainer script cleanups
PATCH 1/3 get_maintainer: fix perlcritic warnings
perlcritic is a standard checker for Perl Best Practices. This patch fixes most of the warnings in the get_maintainer script. If kernel programmers are going to have checkpatch they should write clean scripts as well...
---
Bareword file handle opened at line 176, column 1. See pages 202,204 of PBP. (Severity: 5) Two-argument "open" used at line 176, column 1. See page 207 of PBP. (Severity: 5) Bareword file handle opened at line 207, column 5. See pages 202,204 of PBP. (Severity: 5) Two-argument "open" used at line 207, column 5. See page 207 of PBP. (Severity: 5) Bareword file handle opened at line 246, column 6. See pages 202,204 of PBP. (Severity: 5) Two-argument "open" used at line 246, column 6. See page 207 of PBP. (Severity: 5) Bareword file handle opened at line 258, column 2. See pages 202,204 of PBP. (Severity: 5) Two-argument "open" used at line 258, column 2. See page 207 of PBP. (Severity: 5)
Expression form of "eval" at line 983, column 17. See page 161 of PBP. (Severity: 5) Expression form of "eval" at line 985, column 17. See page 161 of PBP. (Severity: 5) Subroutine prototypes used at line 1186, column 1. See page 194 of PBP. (Severity: 5) Subroutine prototypes used at line 1206, column 1. See page 194 of PBP. (Severity: 5)
scripts/get_maintainer.pl +20 -14
@@ -173,8 +173,9 @@ if (!top_of_kernel_tree($lk_path)) { my @typevalue = (); my %keyword_hash; -open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n"; -while (<MAINT>) { +open (my $maint, '<', "${lk_path}MAINTAINERS") + or die "$P: Can't open MAINTAINERS: $!\n"; +while (<$maint>) { my $line = $_; if ($line =~ m/^(\C):\s*(.*)/) {
@@ -199,13 +200,14 @@ while (<MAINT>) { push(@typevalue, $line); } } -close(MAINT); +close($maint); my %mailmap; if ($email_remove_duplicates) { - open(MAILMAP, "<${lk_path}.mailmap") || warn "$P: Can't open .mailmap\n"; - while (<MAILMAP>) { + open(my $mailmap, '<', "${lk_path}.mailmap") + or warn "$P: Can't open .mailmap: $!\n"; + while (<$mailmap>) { my $line = $_; next if ($line =~ m/^\s*#/);
@@ -224,7 +226,7 @@ if ($email_remove_duplicates) { $mailmap{$name} = \@arr; } } - close(MAILMAP); + close($mailmap); } ## use the filenames on the command line or find the filenames in the patchfiles
@@ -243,20 +245,23 @@ foreach my $file (@ARGV) { if ($from_filename) { push(@files, $file); if (-f $file && $keywords) { - open(FILE, "<$file") or die "$P: Can't open ${file}\n"; - my $text = do { local($/) ; <FILE> }; + open(my $f, '<', $file) + or die "$P: Can't open $file: $!\n"; + my $text = do { local($/) ; <$f> }; foreach my $line (keys %keyword_hash) { if ($text =~ m/$keyword_hash{$line}/x) { push(@keyword_tvi, $line); } } - close(FILE); + close($f); } } else { my $file_cnt = @files; my $lastfile; - open(PATCH, "<$file") or die "$P: Can't open ${file}\n"; - while (<PATCH>) { + + open(my $patch, '<', $file) + or die "$P: Can't open $file: $!\n"; + while (<$patch>) { my $patch_line = $_; if (m/^\+\+\+\s+(\S+)/) { my $filename = $1;
@@ -276,7 +281,8 @@ foreach my $file (@ARGV) { } } } - close(PATCH); + close($patch); + if ($file_cnt == @files) { warn "$P: file '${file}' doesn't appear to be a patch. " . "Add -f to options?\n";
@@ -1183,7 +1189,7 @@ sub rfc822_strip_comments { # valid: returns true if the parameter is an RFC822 valid address # -sub rfc822_valid ($) { +sub rfc822_valid { my $s = rfc822_strip_comments(shift); if (!$rfc822re) {
@@ -1203,7 +1209,7 @@ sub rfc822_valid ($) { # from success with no addresses found, because an empty string is # a valid list. -sub rfc822_validlist ($) { +sub rfc822_validlist { my $s = rfc822_strip_comments(shift); if (!$rfc822re) {
Re: [PATCH 1/3] get_maintainer: fix perlcritic warnings
Quoted 2 lines · Stephen Hemminger
This patch fixes most of the warnings in the
get_maintainerscript.Signed-off-by Stephen Hemminger <[email protected]>
Thanks Stephen.
PATCH 2/3 get_maintainer: use references and closures
In reply to Stephen HemmingerUsing eval on a string is considered bad practice in Perl because of the possiblity of errors at run time. Better to use a closure for the is VCx available test.
scripts/get_maintainer.pl +23 -22
@@ -69,11 +69,11 @@ my $rfc822_char = '[\\000-\\377]'; # VCS command support: class-like functions and strings -my %VCS_cmds; +my $VCS_cmds; my %VCS_cmds_git = ( "execute_cmd" => \&git_execute_cmd, - "available" => '(which("git") ne "") && (-d ".git")', + "available" => sub { (which("git") ne "") && (-d ".git") }, "find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file", "find_commit_signers_cmd" => "git log --no-color -1 \$commit", "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
@@ -84,7 +84,7 @@ my %VCS_cmds_git = ( my %VCS_cmds_hg = ( "execute_cmd" => \&hg_execute_cmd, - "available" => '(which("hg") ne "") && (-d ".hg")', + "available" => sub { (which("hg") ne "") && (-d ".hg") }, "find_signers_cmd" => "hg log --date=\$email_hg_since" . " --template='commit {node}\\n{desc}\\n' -- \$file",
@@ -900,9 +900,9 @@ sub vcs_find_signers { my @lines = (); my $commits; - @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); + @lines = &{$VCS_cmds->{"execute_cmd"}}($cmd); - my $pattern = $VCS_cmds{"commit_pattern"}; + my $pattern = $VCS_cmds->{"commit_pattern"}; $commits = grep(/$pattern/, @lines); # of commits
@@ -928,10 +928,10 @@ sub vcs_save_commits { my @lines = (); my @commits = (); - @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); + @lines = &{$VCS_cmds->{"execute_cmd"}}($cmd); foreach my $line (@lines) { - if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) { + if ($line =~ m/$VCS_cmds->{"blame_commit_pattern"}/) { push(@commits, $1); } }
@@ -946,10 +946,10 @@ sub vcs_blame { return @commits if (!(-f $file)); - if (@range && $VCS_cmds{"blame_range_cmd"} eq "") { + if (@range && $VCS_cmds->{"blame_range_cmd"} eq "") { my @all_commits = (); - $cmd = $VCS_cmds{"blame_file_cmd"}; + $cmd = $VCS_cmds->{"blame_file_cmd"}; $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd @all_commits = vcs_save_commits($cmd);
@@ -970,12 +970,12 @@ sub vcs_blame { my $diff_start = $2; my $diff_length = $3; next if ("$file" ne "$diff_file"); - $cmd = $VCS_cmds{"blame_range_cmd"}; + $cmd = $VCS_cmds->{"blame_range_cmd"}; $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd push(@commits, vcs_save_commits($cmd)); } } else { - $cmd = $VCS_cmds{"blame_file_cmd"}; + $cmd = $VCS_cmds->{"blame_file_cmd"}; $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd @commits = vcs_save_commits($cmd); }
@@ -985,16 +985,17 @@ sub vcs_blame { my $printed_novcs = 0; sub vcs_exists { - %VCS_cmds = %VCS_cmds_git; - return 1 if eval $VCS_cmds{"available"}; - %VCS_cmds = %VCS_cmds_hg; - return 1 if eval $VCS_cmds{"available"}; - %VCS_cmds = (); + $VCS_cmds = \%VCS_cmds_git; + return 1 if eval $VCS_cmds->{"available"}(); + $VCS_cmds = \%VCS_cmds_hg; + return 1 if eval $VCS_cmds->{"available"}(); + $VCS_cmds = undef; + if (!$printed_novcs) { - warn("$P: No supported VCS found. Add --nogit to options?\n"); - warn("Using a git repository produces better results.\n"); - warn("Try Linus Torvalds' latest git repository using:\n"); - warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"); + warn "$P: No supported VCS found. Add --nogit to options?\n", + "Using a git repository produces better results.\n", + "Try Linus Torvalds' latest git repository using:\n", + "git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"; $printed_novcs = 1; } return 0;
@@ -1050,7 +1051,7 @@ sub vcs_file_signoffs { return if (!vcs_exists()); - my $cmd = $VCS_cmds{"find_signers_cmd"}; + my $cmd = $VCS_cmds->{"find_signers_cmd"}; $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd ($commits, @signers) = vcs_find_signers($cmd);
@@ -1074,7 +1075,7 @@ sub vcs_file_blame { my $commit_count; my @commit_signers = (); - my $cmd = $VCS_cmds{"find_commit_signers_cmd"}; + my $cmd = $VCS_cmds->{"find_commit_signers_cmd"}; $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd ($commit_count, @commit_signers) = vcs_find_signers($cmd);
Joe Perches
maintainerRe: [PATCH 2/3] get_maintainer: use references and closures
scripts/get_maintainer.pl sub vcs_blame { · line 999
Quoted 10 lines · Stephen Hemminger
if (!$printed_novcs) {scripts/get_maintainer.pl +4
-4- warn("$P: No supported VCS found. Add --nogit to options?\n"); - warn("Using a git repository produces better results.\n"); - warn("Try Linus Torvalds' latest git repository using:\n"); - warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"); + warn "$P: No supported VCS found. Add --nogit to options?\n", + "Using a git repository produces better results.\n", + "Try Linus Torvalds' latest git repository using:\n", + "git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"; $printed_novcs = 1;
All other quoted string line continuations use periods. Please use periods and resubmit.
PATCH 3/3 get_maintainer: quote email address with period
In reply to Stephen HemmingerPicky mail systems won't accept email addresses where recipient has period in name; ie. David S. Miller <davemloft.net> will not work.
scripts/get_maintainer.pl +2 -2
@@ -551,7 +551,7 @@ sub parse_email { $name =~ s/^\"|\"$//g; $address =~ s/^\s+|\s+$//g; - if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars + if ($name =~ /[^\w \-]/i) { ##has "must quote" chars $name =~ s/(?<!\\)"/\\"/g; ##escape quotes $name = "\"$name\""; }
@@ -568,7 +568,7 @@ sub format_email { $name =~ s/^\"|\"$//g; $address =~ s/^\s+|\s+$//g; - if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars + if ($name =~ /[^\w \-]/i) { ##has "must quote" chars $name =~ s/(?<!\\)"/\\"/g; ##escape quotes $name = "\"$name\""; }
Re: [PATCH 3/3] get_maintainer: quote email address with period
Quoted 5 lines · Stephen Hemminger
plain text document attachment (get-maintainer-vger.patch) Picky mail systems won't accept email addresses where recipient has period in name; ie. David S. Miller <davemloft.net> will not work.
Signed-off-by Stephen Hemminger <[email protected]>