From: Tom Saeger <tom.saeger@oracle.com>
To: Joe Perches <joe@perches.com>
Cc: Tom Saeger <tom.saeger@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/2] scripts: warn about invalid MAINTAINER patterns
Date: Tue, 31 Oct 2017 09:46:12 -0500 [thread overview]
Message-ID: <a35fc984e206942eec67302726f5b642c68909b9.1509401037.git.tom.saeger@oracle.com> (raw)
In-Reply-To: <cover.1509401037.git.tom.saeger@oracle.com>
In-Reply-To: <cover.1509401037.git.tom.saeger@oracle.com>
Add get_maintainer.pl option to warn about invalid
"F" and "X" patterns found in MAINTAINERS file(s).
Signed-off-by: Tom Saeger <tom.saeger@oracle.com>
---
scripts/get_maintainer.pl | 65 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index bc443201d3ef..e01041325ea0 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -19,6 +19,7 @@ my $V = '0.26';
use Getopt::Long qw(:config no_auto_abbrev);
use Cwd;
use File::Find;
+use File::Basename;
my $cur_path = fastgetcwd() . '/';
my $lk_path = "./";
@@ -57,6 +58,7 @@ my $sections = 0;
my $file_emails = 0;
my $from_filename = 0;
my $pattern_depth = 0;
+my $xchecks = 0;
my $version = 0;
my $help = 0;
my $find_maintainer_files = 0;
@@ -138,6 +140,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 +170,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 +256,7 @@ if (!GetOptions(
'fe|file-emails!' => \$file_emails,
'f|file' => \$from_filename,
'find-maintainer-files' => \$find_maintainer_files,
+ 'x|checks' => \$xchecks,
'v|version' => \$version,
'h|help|usage' => \$help,
)) {
@@ -311,12 +316,14 @@ if (!top_of_kernel_tree($lk_path)) {
my @typevalue = ();
my %keyword_hash;
my @mfiles = ();
+my @patternchecks = ();
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 +340,9 @@ sub read_maintainer_file {
if ((-d $value)) {
$value =~ s@([^/])$@$1/@;
}
+ if ($xchecks) {
+ push(@patternchecks, {file=>$file, line=>$line, linenr=>$i, pat=>$value});
+ }
} elsif ($type eq "K") {
$keyword_hash{@typevalue} = $value;
}
@@ -341,6 +351,7 @@ sub read_maintainer_file {
$line =~ s/\n$//g;
push(@typevalue, $line);
}
+ $i++;
}
close($maint);
}
@@ -543,6 +554,11 @@ foreach my $file (@ARGV) {
}
}
+if ($xchecks) {
+ check_maintainer_patterns();
+ exit 0;
+}
+
@file_emails = uniq(@file_emails);
my %email_hash_name;
@@ -584,6 +600,37 @@ if ($web) {
output(@web);
}
+sub has_valid_matches {
+ my ($value, $files) = @_;
+ foreach my $file (@{$files}) {
+ if (file_match_pattern($file, $value)) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+sub check_maintainer_patterns {
+ my @lsfiles = ();
+
+ @lsfiles = vcs_list_files($lk_path);
+
+ # add directories too
+ my @dirs = ();
+ foreach my $f (@lsfiles) {
+ push(@dirs, dirname($f));
+ }
+ push(@lsfiles, uniq(@dirs));
+
+ for my $x (@patternchecks) {
+ if (!has_valid_matches($x->{pat}, \@lsfiles)) {
+ my $line = $x->{line};
+ chomp($line);
+ print("$x->{file}:$x->{linenr}\twarning: no matches\t$x->{pat}\t$line\n");
+ }
+ }
+}
+
exit($exit);
sub ignore_email_address {
@@ -863,6 +910,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)
+ --checks => check for "F" and "X" pattern warnings
--version => show version
--help => show this help information
@@ -2192,6 +2240,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
next prev parent reply other threads:[~2017-10-31 14:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-31 14:46 [RFC PATCH 0/2] " Tom Saeger
2017-10-31 14:46 ` Tom Saeger [this message]
2017-10-31 15:47 ` [RFC PATCH 1/2] " Joe Perches
2017-10-31 15:50 ` Tom Saeger
2017-10-31 14:46 ` [RFC PATCH 2/2] MAINTAINERS: various pattern fixes for mv/rm/typos Tom Saeger
2017-10-31 15:55 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a35fc984e206942eec67302726f5b642c68909b9.1509401037.git.tom.saeger@oracle.com \
--to=tom.saeger@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®