2 # SPDX-License-Identifier: GPL-2.0
5 use Getopt::Long qw(:config no_auto_abbrev);
7 my $input_file = "MAINTAINERS";
8 my $output_file = "MAINTAINERS.new";
9 my $output_section = "SECTION.new";
15 'input=s' => \$input_file,
16 'output=s' => \$output_file,
17 'section=s' => \$output_section,
19 'h|help|usage' => \$help,
21 die "$P: invalid argument - use --help if necessary\n";
31 usage: $P [options] <pattern matching regexes>
33 --input => MAINTAINERS file to read (default: MAINTAINERS)
34 --output => sorted MAINTAINERS file to write (default: MAINTAINERS.new)
35 --section => new sorted MAINTAINERS file to write to (default: SECTION.new)
36 --order => Use the preferred section content output ordering (default: 0)
37 Preferred ordering of section output is:
38 M: Person acting as a maintainer
39 R: Person acting as a patch reviewer
40 L: Mailing list where patches should be sent
42 W: URI for general information
43 Q: URI for patchwork tracking
44 B: URI for bug tracking/submission
46 P: URI or file for subsystem specific coding styles
47 T: SCM tree type and location
48 F: File and directory pattern
49 X: File and directory exclusion pattern
51 K: Keyword - patch content regex
53 If <pattern match regexes> exist, then the sections that match the
54 regexes are not written to the output file but are written to the
60 # sort comparison functions
67 # This always sorts last
68 $a =~ s/THE REST/ZZZZZZ/g;
69 $b =~ s/THE REST/ZZZZZZ/g;
76 my $preferred_order = 'MRLSWQBCPTFXNK';
78 my $a1 = uc(substr($a, 0, 1));
79 my $b1 = uc(substr($b, 0, 1));
81 my $a_index = index($preferred_order, $a1);
82 my $b_index = index($preferred_order, $b1);
84 $a_index = 1000 if ($a_index == -1);
85 $b_index = 1000 if ($b_index == -1);
87 if (($a1 =~ /^F$/ && $b1 =~ /^F$/) ||
88 ($a1 =~ /^X$/ && $b1 =~ /^X$/)) {
92 if ($a_index < $b_index) {
94 } elsif ($a_index == $b_index) {
109 my ($hashref, $filename) = (@_);
111 return if ! scalar(keys %$hashref);
113 open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
115 foreach my $key (sort by_category keys %$hashref) {
117 print $file $$hashref{$key};
119 if (! defined $separator) {
122 print $file $separator;
124 print $file $key . "\n";
126 foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
127 print $file ($pattern . "\n");
130 foreach my $pattern (split('\n', %$hashref{$key})) {
131 print $file ($pattern . "\n");
140 my ($hashref, $filename) = (@_);
144 $$hashref{$case} = "";
146 open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n";
152 if ($line =~ m/^([A-Z]):\s*(.*)/) {
153 $line = $1 . ":\t" . trim($2) . "\n";
154 if ($lastline eq "") {
155 $$hashref{$case} = $$hashref{$case} . $line;
158 $case = trim($lastline);
159 exists $$hashref{$case} and die "Header '$case' already exists";
160 $$hashref{$case} = $line;
166 $$hashref{$case} = $$hashref{$case} . $lastline;
170 trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
173 $$hashref{$case} = $$hashref{$case} . $lastline;
180 file_input(\%hash, $input_file);
182 foreach my $type (@ARGV) {
183 foreach my $key (keys %hash) {
184 if ($key =~ /$type/ || $hash{$key} =~ /$type/) {
185 $new_hash{$key} = $hash{$key};
191 alpha_output(\%hash, $output_file);
192 alpha_output(\%new_hash, $output_section);