parse-maintainers: Add section pattern sorting

Section [A-Z]: patterns are not currently in any required sorting order.
Add a specific sorting sequence to MAINTAINERS entries.
Sort F: and X: patterns in alphabetic order.

The preferred section ordering is:

  SECTION HEADER
  M:	Maintainers
  R:	Reviewers
  P:	Named persons without email addresses
  L:	Mailing list addresses
  S:	Status of this section (Supported, Maintained, Orphan, etc...)
  W:	Any relevant URLs
  T:	Source code control type (git, quilt, etc)
  Q:	Patchwork patch acceptance queue site
  B:	Bug tracking URIs
  C:	Chat URIs
  F:	Files with wildcard patterns (alphabetic ordered)
  X:	Excluded files with wildcard patterns (alphabetic ordered)
  N:	Files with regex patterns
  K:	Keyword regexes in source code for maintainership identification

Miscellaneous perl neatening:

 - Rename %map to %hash, map has a different meaning in perl
 - Avoid using \& and local variables for function indirection
 - Use return for a little c like clarity
 - Use c-like function call style instead of &function

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Joe Perches 2017-08-05 18:45:47 -07:00 committed by Linus Torvalds
parent 6f7d98ec44
commit 61f741645a
1 changed files with 49 additions and 21 deletions

View File

@ -2,9 +2,9 @@
use strict; use strict;
my %map; my %hash;
# sort comparison function # sort comparison functions
sub by_category($$) { sub by_category($$) {
my ($a, $b) = @_; my ($a, $b) = @_;
@ -15,20 +15,47 @@ sub by_category($$) {
$a =~ s/THE REST/ZZZZZZ/g; $a =~ s/THE REST/ZZZZZZ/g;
$b =~ s/THE REST/ZZZZZZ/g; $b =~ s/THE REST/ZZZZZZ/g;
$a cmp $b; return $a cmp $b;
}
sub by_pattern($$) {
my ($a, $b) = @_;
my $preferred_order = 'MRPLSWTQBCFXNK';
my $a1 = uc(substr($a, 0, 1));
my $b1 = uc(substr($b, 0, 1));
my $a_index = index($preferred_order, $a1);
my $b_index = index($preferred_order, $b1);
$a_index = 1000 if ($a_index == -1);
$b_index = 1000 if ($b_index == -1);
if (($a1 =~ /^F$/ && $b1 =~ /^F$/) ||
($a1 =~ /^X$/ && $b1 =~ /^X$/)) {
return $a cmp $b;
}
if ($a_index < $b_index) {
return -1;
} elsif ($a_index == $b_index) {
return 0;
} else {
return 1;
}
} }
sub alpha_output { sub alpha_output {
my $key; foreach my $key (sort by_category keys %hash) {
my $sort_method = \&by_category; if ($key eq " ") {
my $sep = ""; chomp $hash{$key};
print $hash{$key};
foreach $key (sort $sort_method keys %map) { } else {
if ($key ne " ") { print "\n" . $key . "\n";
print $sep . $key . "\n"; foreach my $pattern (sort by_pattern split('\n', $hash{$key})) {
$sep = "\n"; print($pattern . "\n");
} }
print $map{$key}; }
} }
} }
@ -42,7 +69,7 @@ sub trim {
sub file_input { sub file_input {
my $lastline = ""; my $lastline = "";
my $case = " "; my $case = " ";
$map{$case} = ""; $hash{$case} = "";
while (<>) { while (<>) {
my $line = $_; my $line = $_;
@ -51,27 +78,28 @@ sub file_input {
if ($line =~ m/^([A-Z]):\s*(.*)/) { if ($line =~ m/^([A-Z]):\s*(.*)/) {
$line = $1 . ":\t" . trim($2) . "\n"; $line = $1 . ":\t" . trim($2) . "\n";
if ($lastline eq "") { if ($lastline eq "") {
$map{$case} = $map{$case} . $line; $hash{$case} = $hash{$case} . $line;
next; next;
} }
$case = trim($lastline); $case = trim($lastline);
exists $map{$case} and die "Header '$case' already exists"; exists $hash{$case} and die "Header '$case' already exists";
$map{$case} = $line; $hash{$case} = $line;
$lastline = ""; $lastline = "";
next; next;
} }
if ($case eq " ") { if ($case eq " ") {
$map{$case} = $map{$case} . $lastline; $hash{$case} = $hash{$case} . $lastline;
$lastline = $line; $lastline = $line;
next; next;
} }
trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'"); trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
$lastline = $line; $lastline = $line;
} }
$map{$case} = $map{$case} . $lastline; $hash{$case} = $hash{$case} . $lastline;
} }
&file_input; file_input();
&alpha_output; alpha_output();
exit(0); exit(0);