Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1694351

Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering

From Linus Torvalds <torvalds@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering
Date 2017-07-23 21:50 +0200
Message-ID <u6v33-3ff-3@gated-at.bofh.it> (permalink)
References <u5MSl-ZJ-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Ok, so I already applied your alpha-ordering patch, but it just annoyed me that

 (a) the ordering wasn't complete

 (b) this wasn't scripted.

However, the sane way of scripting it is clearly not to do it in C,
which I'd be comfy with, because that would be insane.

Instead, it should be done in perl. Except my perl-fu is so horribly
horribly bad that I'm a bit ashamed to show the end result.

Does anybody have actual real perl skills? Because somebody should
double-check my appended script-from-hell.

ANYWAY. One reason I did this was because *if* we want to split up the
MAINTAINERS file, I absolutely refuse to do it by hand. It needs to be
automated. I'm not going to apply a patch - I'm going to apply a
*script*, and commit the end result along with the doc about what the
script was (so that then I have an inevitable conflict due to this big
re-org, I can resolve the conflict by re-running the script on the
side that wasn't part of the re-org, rather than having to do nasty
things).

And this script could easily be extended to automate the scripting. So
please, can somebody with perl-fu say that "yeah, that's the right
perl model", or point me to what I did wrong?

The end result looks ok. I can run

    perl parse-maintainers.pl < MAINTAINERS > outfile

and the end result is actually a *properly* sorted MAINTAINERS file as
far as I can tell.

Comments?

                   Linus

---
#!/usr/bin/perl -w

use strict;

my %map;

# sort comparison function
sub by_category($$) {
    my ($a, $b) = @_;

    $a = uc $a;
    $b = uc $b;

    # This always sorts last
    $a =~ s/THE REST/ZZZZZZ/g;
    $b =~ s/THE REST/ZZZZZZ/g;

    $a cmp $b;
}

sub alpha_output {
    my $key;
    my $sort_method = \&by_category;

    foreach $key (sort $sort_method keys %map) {
        if ($key ne " ") {
            print $key;
        }
        print $map{$key};
    }
}

sub file_input {
    my $lastline = "";
    my $case = " ";
    $map{$case} = "";

    while (<>) {
        my $line = $_;

        # Pattern line?
        if ($line =~ m/^([A-Z]):\s*(.*)/) {
            if ($lastline eq "") {
                $map{$case} = $map{$case} . $line;
                next;
            }
            $case = $lastline;
            $map{$case} = $line;
            $lastline = "";
            next;
        }

        $map{$case} = $map{$case} . $lastline;
        $lastline = $line;
    }
    $map{$case} = $map{$case} . $lastline;
}

&file_input;
&alpha_output;
exit(0);

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Linus Torvalds <torvalds@linux-foundation.org> - 2017-07-23 21:50 +0200
  Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Linus Torvalds <torvalds@linux-foundation.org> - 2017-07-23 22:10 +0200
    Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Joe Perches <joe@perches.com> - 2017-07-23 22:20 +0200
    Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Linus Torvalds <torvalds@linux-foundation.org> - 2017-07-24 01:20 +0200
      Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Joe Perches <joe@perches.com> - 2017-07-24 03:40 +0200
      Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Joe Perches <joe@perches.com> - 2017-07-28 02:40 +0200
        Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Linus Torvalds <torvalds@linux-foundation.org> - 2017-07-28 04:50 +0200
          Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Joe Perches <joe@perches.com> - 2017-07-28 05:20 +0200
            Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Linus Torvalds <torvalds@linux-foundation.org> - 2017-07-29 00:40 +0200
              Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Joe Perches <joe@perches.com> - 2017-07-29 03:10 +0200
              Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Joe Perches <joe@perches.com> - 2017-07-29 19:50 +0200
  Re: [PATCH Y.A. RESEND] MAINTAINERS: fix alpha. ordering Joe Perches <joe@perches.com> - 2017-07-23 22:10 +0200

csiph-web