linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: warn about invalid MAINTAINERS patterns
@ 2017-10-31 21:37 Tom Saeger
  2017-11-01 15:32 ` Joe Perches
  2017-11-01 16:50 ` Joe Perches
  0 siblings, 2 replies; 9+ messages in thread
From: Tom Saeger @ 2017-10-31 21:37 UTC (permalink / raw)
  To: Joe Perches, linux-kernel; +Cc: Tom Saeger

Add "--pattern-checks" option to get_maintainer.pl to warn about invalid
"F" and "X" patterns found in MAINTAINERS file(s).

Signed-off-by: Tom Saeger <tom.saeger@oracle.com>
Cc: Joe Perches <joe@perches.com>
---
 scripts/get_maintainer.pl | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index bc443201d3ef..ab741b022405 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 $pattern_checks = 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");
@@ -252,6 +255,7 @@ if (!GetOptions(
 		'fe|file-emails!' => \$file_emails,
 		'f|file' => \$from_filename,
 		'find-maintainer-files' => \$find_maintainer_files,
+		'pattern-checks' => \$pattern_checks,
 		'v|version' => \$version,
 		'h|help|usage' => \$help,
 		)) {
@@ -311,12 +315,14 @@ if (!top_of_kernel_tree($lk_path)) {
 my @typevalue = ();
 my %keyword_hash;
 my @mfiles = ();
+my @pattern_checks_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 +339,9 @@ sub read_maintainer_file {
 		if ((-d $value)) {
 		    $value =~ s@([^/])$@$1/@;
 		}
+		if ($pattern_checks) {
+			push(@pattern_checks_info, {file=>$file, line=>$line, linenr=>$i, pat=>$value});
+		}
 	    } elsif ($type eq "K") {
 		$keyword_hash{@typevalue} = $value;
 	    }
@@ -341,6 +350,7 @@ sub read_maintainer_file {
 	    $line =~ s/\n$//g;
 	    push(@typevalue, $line);
 	}
+	$i++;
     }
     close($maint);
 }
@@ -543,6 +553,11 @@ foreach my $file (@ARGV) {
     }
 }
 
+if ($pattern_checks) {
+    check_maintainers_patterns();
+    exit 0;
+}
+
 @file_emails = uniq(@file_emails);
 
 my %email_hash_name;
@@ -586,6 +601,20 @@ if ($web) {
 
 exit($exit);
 
+sub check_maintainers_patterns {
+    my @lsfiles = ();
+
+    @lsfiles = vcs_list_files($lk_path);
+
+    for my $x (@pattern_checks_info) {
+        if (!grep(m@^$x->{pat}@, @lsfiles)) {
+            my $line = $x->{line};
+            chomp($line);
+            print(STDERR "$x->{file}:$x->{linenr}\twarning: no matches\t$line\n");
+        }
+    }
+}
+
 sub ignore_email_address {
     my ($address) = @_;
 
@@ -863,6 +892,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)
+  --pattern-checks => warn about invalid "F" and "X" patterns in MAINTAINERS file
   --version => show version
   --help => show this help information
 
@@ -2192,6 +2222,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) = @_;
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-11-01 20:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-31 21:37 [PATCH] scripts: warn about invalid MAINTAINERS patterns Tom Saeger
2017-11-01 15:32 ` Joe Perches
2017-11-01 16:05   ` Tom Saeger
2017-11-01 16:50 ` Joe Perches
2017-11-01 17:11   ` Tom Saeger
2017-11-01 20:05     ` Augie Fackler
2017-11-01 20:24       ` Joe Perches
2017-11-01 18:13   ` [PATCH v2 1/1] " Tom Saeger
2017-11-01 18:33     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).