lkml.org 
[lkml]   [2017]   [Jul]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering
From
Date
On Sun, 2017-07-23 at 16:14 -0700, Linus Torvalds wrote:
> On Sun, Jul 23, 2017 at 1:00 PM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > Anyway, clearly my script showed something. I think my script is still
> > doing the right thing, it's just that the input is questionable.
>
> I added a few actual checks for the error cases to the script, fixed
> up the problems, and committed the end result.
>
> My perl skills are still very dubious, so I'm not proud of the script,
> but it's there as "scripts/parse-mainainers.pl" now. The "output
> sorted result" part could *easily* be changed into "output sorted
> result into separate files based on the first word of the header" or
> something.
>
> But in the meantime, at least that MAINTAINERS file should _really_ be
> alpha-sorted now.

Maybe add a reordering of the patterns so that each pattern list
is in a specific order too

---
 scripts/parse-maintainers.pl | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/scripts/parse-maintainers.pl b/scripts/parse-maintainers.pl
index a0fe34349b24..03e7405af1a3 100644
--- a/scripts/parse-maintainers.pl
+++ b/scripts/parse-maintainers.pl
@@ -4,7 +4,7 @@ use strict;
 
 my %map;
 
-# sort comparison function
+# sort comparison functions
 sub by_category($$) {
     my ($a, $b) = @_;
 
@@ -18,17 +18,45 @@ sub by_category($$) {
     $a cmp $b;
 }
 
+sub by_pattern($$) {
+    my ($a, $b) = @_;
+    my $preferred_order = 'MRPLWQTBSKCFX';
+
+    my $rtn;
+    $a = uc(substr($a, 0, 1));
+    $b = uc(substr($b, 0, 1));
+
+    my $a_index = index($preferred_order, $a);
+    my $b_index = index($preferred_order, $b);
+
+    $a_index = 1000 if ($a_index == -1);
+    $b_index = 1000 if ($b_index == -1);
+
+    if ($a_index < $b_index) {
+ return -1;
+    } elsif ($a_index == $b_index) {
+ return 0;
+    } else {
+ return 1;
+    }
+}
+
 sub alpha_output {
     my $key;
-    my $sort_method = \&by_category;
     my $sep = "";
 
-    foreach $key (sort $sort_method keys %map) {
+    foreach $key (sort by_category keys %map) {
         if ($key ne " ") {
             print $sep . $key . "\n";
             $sep = "\n";
         }
-        print $map{$key};
+ if ($key eq " ") {
+     print $map{$key};
+ } else {
+     foreach my $pattern (sort by_pattern split('\n', $map{$key})) {
+ print($pattern . "\n");
+     }
+ }
     }
 }
 

\
 
 \ /
  Last update: 2017-07-28 02:30    [W:0.070 / U:4.660 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site