git-shortlog.perlon commit Merge early part of 'jc/combine' branch (b411fda)
   1#!/usr/bin/perl -w
   2
   3use strict;
   4
   5my (%mailmap);
   6my (%email);
   7my (%map);
   8my $pstate = 1;
   9my $n_records = 0;
  10my $n_output = 0;
  11
  12sub shortlog_entry($$) {
  13        my ($name, $desc) = @_;
  14        my $key = $name;
  15
  16        $desc =~ s#/pub/scm/linux/kernel/git/#/.../#g;
  17        $desc =~ s#\[PATCH\] ##g;
  18
  19        # store description in array, in email->{desc list} map
  20        if (exists $map{$key}) {
  21                # grab ref
  22                my $obj = $map{$key};
  23
  24                # add desc to array
  25                push(@$obj, $desc);
  26        } else {
  27                # create new array, containing 1 item
  28                my @arr = ($desc);
  29
  30                # store ref to array
  31                $map{$key} = \@arr;
  32        }
  33}
  34
  35# sort comparison function
  36sub by_name($$) {
  37        my ($a, $b) = @_;
  38
  39        uc($a) cmp uc($b);
  40}
  41
  42sub shortlog_output {
  43        my ($obj, $key, $desc);
  44
  45        foreach $key (sort by_name keys %map) {
  46                # output author
  47                printf "%s:\n", $key;
  48
  49                # output author's 1-line summaries
  50                $obj = $map{$key};
  51                foreach $desc (reverse @$obj) {
  52                        print "  $desc\n";
  53                        $n_output++;
  54                }
  55
  56                # blank line separating author from next author
  57                print "\n";
  58        }
  59}
  60
  61sub changelog_input {
  62        my ($author, $desc);
  63
  64        while (<>) {
  65                # get author and email
  66                if ($pstate == 1) {
  67                        my ($email);
  68
  69                        next unless /^[Aa]uthor:?\s*(.*?)\s*<(.*)>/;
  70
  71                        $n_records++;
  72
  73                        $author = $1;
  74                        $email = $2;
  75                        $desc = undef;
  76
  77                        # cset author fixups
  78                        if (exists $mailmap{$email}) {
  79                                $author = $mailmap{$email};
  80                        } elsif (exists $mailmap{$author}) {
  81                                $author = $mailmap{$author};
  82                        } elsif (!$author) {
  83                                $author = $email;
  84                        }
  85                        $email{$author}{$email}++;
  86                        $pstate++;
  87                }
  88
  89                # skip to blank line
  90                elsif ($pstate == 2) {
  91                        next unless /^\s*$/;
  92                        $pstate++;
  93                }
  94
  95                # skip to non-blank line
  96                elsif ($pstate == 3) {
  97                        next unless /^\s*?(.*)/;
  98
  99                        # skip lines that are obviously not
 100                        # a 1-line cset description
 101                        next if /^\s*From: /;
 102
 103                        chomp;
 104                        $desc = $1;
 105
 106                        &shortlog_entry($author, $desc);
 107
 108                        $pstate = 1;
 109                }
 110        
 111                else {
 112                        die "invalid parse state $pstate";
 113                }
 114        }
 115}
 116
 117sub read_mailmap {
 118        my ($fh, $mailmap) = @_;
 119        while (<$fh>) {
 120                chomp;
 121                if (/^([^#].*?)\s*<(.*)>/) {
 122                        $mailmap->{$2} = $1;
 123                }
 124        }
 125}
 126
 127sub setup_mailmap {
 128        read_mailmap(\*DATA, \%mailmap);
 129        if (-f '.mailmap') {
 130                my $fh = undef;
 131                open $fh, '<', '.mailmap';
 132                read_mailmap($fh, \%mailmap);
 133                close $fh;
 134        }
 135}
 136
 137sub finalize {
 138        #print "\n$n_records records parsed.\n";
 139
 140        if ($n_records != $n_output) {
 141                die "parse error: input records != output records\n";
 142        }
 143        if (0) {
 144                for my $author (sort keys %email) {
 145                        my $e = $email{$author};
 146                        for my $email (sort keys %$e) {
 147                                print STDERR "$author <$email>\n";
 148                        }
 149                }
 150        }
 151}
 152
 153&setup_mailmap;
 154&changelog_input;
 155&shortlog_output;
 156&finalize;
 157exit(0);
 158
 159
 160__DATA__
 161#
 162# Even with git, we don't always have name translations.
 163# So have an email->real name table to translate the
 164# (hopefully few) missing names
 165#
 166Adrian Bunk <bunk@stusta.de>
 167Andreas Herrmann <aherrman@de.ibm.com>
 168Andrew Morton <akpm@osdl.org>
 169Andrew Vasquez <andrew.vasquez@qlogic.com>
 170Christoph Hellwig <hch@lst.de>
 171Corey Minyard <minyard@acm.org>
 172David Woodhouse <dwmw2@shinybook.infradead.org>
 173Domen Puncer <domen@coderock.org>
 174Douglas Gilbert <dougg@torque.net>
 175Ed L Cashin <ecashin@coraid.com>
 176Evgeniy Polyakov <johnpol@2ka.mipt.ru>
 177Felix Moeller <felix@derklecks.de>
 178Frank Zago <fzago@systemfabricworks.com>
 179Greg Kroah-Hartman <gregkh@suse.de>
 180James Bottomley <jejb@mulgrave.(none)>
 181James Bottomley <jejb@titanic.il.steeleye.com>
 182Jeff Garzik <jgarzik@pretzel.yyz.us>
 183Jens Axboe <axboe@suse.de>
 184Kay Sievers <kay.sievers@vrfy.org>
 185Mitesh shah <mshah@teja.com>
 186Morten Welinder <terra@gnome.org>
 187Morten Welinder <welinder@anemone.rentec.com>
 188Morten Welinder <welinder@darter.rentec.com>
 189Morten Welinder <welinder@troll.com>
 190Nguyen Anh Quynh <aquynh@gmail.com>
 191Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
 192Peter A Jonsson <pj@ludd.ltu.se>
 193Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
 194Rudolf Marek <R.Marek@sh.cvut.cz>
 195Rui Saraiva <rmps@joel.ist.utl.pt>
 196Sachin P Sant <ssant@in.ibm.com>
 197Santtu Hyrkk\e,Av\e(B <santtu.hyrkko@gmail.com>
 198Simon Kelley <simon@thekelleys.org.uk>
 199Tejun Heo <htejun@gmail.com>
 200Tony Luck <tony.luck@intel.com>