From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754832AbdKAPc5 (ORCPT ); Wed, 1 Nov 2017 11:32:57 -0400 Received: from smtprelay0226.hostedemail.com ([216.40.44.226]:45408 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754712AbdKAPcz (ORCPT ); Wed, 1 Nov 2017 11:32:55 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 30,2,0,,d41d8cd98f00b204,joe@perches.com,:::,RULES_HIT:2:41:355:379:541:599:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1381:1437:1515:1516:1518:1535:1593:1594:1605:1606:1730:1747:1777:1792:2197:2199:2393:2559:2562:2828:2892:3138:3139:3140:3141:3142:3622:3653:3865:3866:3867:3868:3870:3871:3872:4250:4321:4605:5007:6119:6299:7903:8957:9040:9163:9545:10004:10848:11026:11232:11658:11914:12043:12291:12296:12438:12555:12679:12683:12740:12760:12895:12986:13149:13230:13439:14659:21080:21221:21324:21433:21451:21505:21627:30003:30022:30054:30062:30069:30070:30075:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: trip39_36541864d8828 X-Filterd-Recvd-Size: 5884 Message-ID: <1509550371.31043.31.camel@perches.com> Subject: Re: [PATCH] scripts: warn about invalid MAINTAINERS patterns From: Joe Perches To: Tom Saeger , linux-kernel@vger.kernel.org Date: Wed, 01 Nov 2017 08:32:51 -0700 In-Reply-To: <20171031213740.25510-1-tom.saeger@oracle.com> References: <20171031213740.25510-1-tom.saeger@oracle.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2017-10-31 at 16:37 -0500, Tom Saeger wrote: > Add "--pattern-checks" option to get_maintainer.pl to warn about invalid > "F" and "X" patterns found in MAINTAINERS file(s). Hey Tom. I've come around to this addition, but I think a few changes are useful. o Change --pattern-checks to --self-test so future checks can be added (valid email address, .mailmap uses, existence of git trees, etc...) o Do not require an unnecessary argument with --self-test o Validate --self-test if it is the only command line argument o Use emacs filename:line: style output for easier linking o --self-test emits to STDOUT not STDERR --- scripts/get_maintainer.pl | 59 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl index bc443201d3ef..128bc90f7034 100755 --- a/scripts/get_maintainer.pl +++ b/scripts/get_maintainer.pl @@ -57,6 +57,7 @@ my $sections = 0; my $file_emails = 0; my $from_filename = 0; my $pattern_depth = 0; +my $self_test = 0; my $version = 0; my $help = 0; my $find_maintainer_files = 0; @@ -138,6 +139,7 @@ my %VCS_cmds_git = ( "subject_pattern" => "^GitSubject: (.*)", "stat_pattern" => "^(\\d+)\\t(\\d+)\\t\$file\$", "file_exists_cmd" => "git ls-files \$file", + "list_files_cmd" => "git ls-files \$file", ); my %VCS_cmds_hg = ( @@ -167,6 +169,7 @@ my %VCS_cmds_hg = ( "subject_pattern" => "^HgSubject: (.*)", "stat_pattern" => "^(\\d+)\t(\\d+)\t\$file\$", "file_exists_cmd" => "hg files \$file", + "list_files_cmd" => "hg files \$file", ); my $conf = which_conf(".get_maintainer.conf"); @@ -216,6 +219,14 @@ if (-f $ignore_file) { close($ignore); } +if ($#ARGV > 0) { + foreach (@ARGV) { + if ($_ eq "-self-test" || $_ eq "--self-test") { + die "$P: using --self-test does not allow any other option or argument\n"; + } + } +} + if (!GetOptions( 'email!' => \$email, 'git!' => \$email_git, @@ -252,6 +263,7 @@ if (!GetOptions( 'fe|file-emails!' => \$file_emails, 'f|file' => \$from_filename, 'find-maintainer-files' => \$find_maintainer_files, + 'self-test' => \$self_test, 'v|version' => \$version, 'h|help|usage' => \$help, )) { @@ -268,7 +280,7 @@ if ($version != 0) { exit 0; } -if (-t STDIN && !@ARGV) { +if (!$self_test && -t STDIN && !@ARGV) { # We're talking to a terminal, but have no command line arguments. die "$P: missing patchfile or -f file - use --help if necessary\n"; } @@ -311,12 +323,14 @@ if (!top_of_kernel_tree($lk_path)) { my @typevalue = (); my %keyword_hash; my @mfiles = (); +my @check_pattern_info = (); sub read_maintainer_file { my ($file) = @_; open (my $maint, '<', "$file") or die "$P: Can't open MAINTAINERS file '$file': $!\n"; + my $i = 1; while (<$maint>) { my $line = $_; @@ -333,6 +347,9 @@ sub read_maintainer_file { if ((-d $value)) { $value =~ s@([^/])$@$1/@; } + if ($self_test) { + push(@check_pattern_info, {file=>$file, linenr=>$i, line=>$line, pat=>$value}); + } } elsif ($type eq "K") { $keyword_hash{@typevalue} = $value; } @@ -341,6 +358,7 @@ sub read_maintainer_file { $line =~ s/\n$//g; push(@typevalue, $line); } + $i++; } close($maint); } @@ -464,7 +482,7 @@ my @range = (); my @keyword_tvi = (); my @file_emails = (); -if (!@ARGV) { +if (!$self_test && !@ARGV) { push(@ARGV, "&STDIN"); } @@ -543,6 +561,11 @@ foreach my $file (@ARGV) { } } +if ($self_test) { + check_maintainers_patterns(); + exit 0; +} + @file_emails = uniq(@file_emails); my %email_hash_name; @@ -586,6 +609,20 @@ if ($web) { exit($exit); +sub check_maintainers_patterns { + my @lsfiles = (); + + @lsfiles = vcs_list_files($lk_path); + + for my $x (@check_pattern_info) { + if (!grep(m@^$x->{pat}@, @lsfiles)) { + my $line = $x->{line}; + chomp($line); + print("$x->{file}:$x->{linenr}:\twarning: no matches\t$line\n"); + } + } +} + sub ignore_email_address { my ($address) = @_; @@ -863,6 +900,7 @@ Other options: --sections => print all of the subsystem sections with pattern matches --letters => print all matching 'letter' types from all matching sections --mailmap => use .mailmap file (default: $email_use_mailmap) + --self-test => show possible invalid MAINTAINERS file content --version => show version --help => show this help information @@ -2192,6 +2230,23 @@ sub vcs_file_exists { return $exists; } +sub vcs_list_files { + my ($file) = @_; + + my @lsfiles = (); + + my $vcs_used = vcs_exists(); + return 0 if (!$vcs_used); + + my $cmd = $VCS_cmds{"list_files_cmd"}; + $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd + @lsfiles = &{$VCS_cmds{"execute_cmd"}}($cmd); + + return () if ($? != 0); + + return @lsfiles; +} + sub uniq { my (@parms) = @_;