[PATCH 3/3] get_maintainer: add patch-only pattern matching type

From: Justin Stitt
Date: Wed Sep 27 2023 - 00:27:11 EST


Add the "D:" type which behaves the same as "K:" but will only match
content present in a patch file.

To illustrate:

Imagine this entry in MAINTAINERS:

NEW REPUBLIC
M: Han Solo <hansolo@xxxxxxxxxxxxxxxx>
W: https://www.jointheresistance.org
D: \bstrncpy\b

Our maintainer, Han, will only be added to the recipients if a patch
file is passed to get_maintainer (like what b4 does):
$ ./scripts/get_maintainer.pl 0004-some-change.patch

If the above patch has a `strncpy` present in the subject, commit log or
diff then Han will be to/cc'd.

However, in the event of a file from the tree given like:
$ ./scripts/get_maintainer.pl ./lib/string.c

Han will not be noisily to/cc'd (like a K: type would in this
circumstance)

Note that folks really shouldn't be using get_maintainer on tree files
anyways [1].

[1]: https://lore.kernel.org/all/20230726151515.1650519-1-kuba@xxxxxxxxxx/
---
scripts/get_maintainer.pl | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index e679eac96793..f290bf0948f1 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -309,6 +309,7 @@ if ( $tree && !top_of_kernel_tree($lk_path) ) {

my @typevalue = ();
my %keyword_hash;
+my %patch_keyword_hash;
my @mfiles = ();
my @self_test_info = ();

@@ -339,6 +340,9 @@ sub read_maintainer_file {
elsif ( $type eq "K" ) {
$keyword_hash{@typevalue} = $value;
}
+ elsif ( $type eq "D" ) {
+ $patch_keyword_hash{@typevalue} = $value;
+ }
push( @typevalue, "$type:$value" );
}
elsif ( !( /^\s*$/ || /^\s*\#/ ) ) {
@@ -591,6 +595,11 @@ foreach my $file (@ARGV) {
push( @keyword_tvi, $line );
}
}
+ foreach my $line ( keys %patch_keyword_hash ) {
+ if ($patch_line =~ m/${patch_prefix}$patch_keyword_hash{$line}/x ) {
+ push( @keyword_tvi, $line );
+ }
+ }
}
}
close($patch);

--
2.42.0.582.g8ccd20d70d-goog