THE REST matches every file in the tree via "F: *" and "F: */", so
get_maintainer.pl currently adds [email protected] to every
patch, regardless of whether the touched files already belong to a
subsystem with its own mailing list.

Only add THE REST for a file when no other matching section provides a
mailing list that get_maintainer.pl would actually output. Lists marked
"subscribers-only" are omitted unless --s is given, and lists marked
"moderated" are omitted with --no-moderated, so such lists don't count
as a destination in those cases. Files that match no section, or only
sections without such a list, still fall back to THE REST, so every
patch keeps reaching at least one known-public mailing list.

Signed-off-by: Konstantin Ryabitsev <[email protected]>
---
 scripts/get_maintainer.pl | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 16b80a700d4a..265245e568c6 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -959,6 +959,15 @@ sub get_maintainers {
            $tvi = $end + 1;
        }
 
+       # THE REST matches every file, so only fall back to it when no
+       # other matching section provides a mailing list for this file
+       # that we would actually output with the current options.
+       my ($the_rest) = grep { get_section_name($_) eq "THE REST" } keys %hash;
+       if (defined($the_rest) &&
+           grep { $_ != $the_rest && section_has_list($_) } keys %hash) {
+           delete $hash{$the_rest};
+       }
+
        foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
            add_categories($line, "");
            if ($sections) {
@@ -1295,6 +1304,40 @@ sub find_ending_index {
     return $index;
 }
 
+sub get_section_name {
+    my ($index) = @_;
+
+    return $typevalue[find_starting_index($index)];
+}
+
+sub section_has_list {
+    my ($index) = @_;
+
+    my $start = find_starting_index($index);
+    my $end = find_ending_index($index);
+    for (my $i = $start; $i < $end; $i++) {
+       next if ($typevalue[$i] !~ m/^L:\s*(.*)/);
+       my $list_additional = "";
+       if ($1 =~ m/[^\s]+\s+(.*)$/) {
+           $list_additional = $1;
+       }
+       return 1 if (list_is_selected($list_additional));
+    }
+    return 0;
+}
+
+# Must match the list selection in add_categories()
+sub list_is_selected {
+    my ($list_additional) = @_;
+
+    if ($list_additional =~ m/subscribers-only/) {
+       return $email_subscriber_list;
+    } elsif ($list_additional =~ m/moderated/) {
+       return $email_list && $email_moderated_list;
+    }
+    return $email_list;
+}
+
 sub get_subsystem_name {
     my ($index) = @_;
 

-- 
2.55.0


Reply via email to