-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-shortlog
executable file
·177 lines (143 loc) · 3.8 KB
/
git-shortlog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/perl -w
use strict;
#
# Even with git, we don't always have name translations.
# So have an email->real name table to translate the
# (hopefully few) missing names
#
my %mailmap = (
'[email protected]' => 'Rudolf Marek',
'[email protected]' => 'Ralf Wildenhues',
'[email protected]' => 'Andreas Herrmann',
'[email protected]' => 'Andrew Morton',
'[email protected]' => 'Andrew Vasquez',
'[email protected]' => 'Nguyen Anh Quynh',
'[email protected]' => 'Jens Axboe',
'[email protected]' => 'Paolo \'Blaisorblade\' Giarrusso',
'[email protected]' => 'Adrian Bunk',
'[email protected]' => 'Domen Puncer',
'[email protected]' => 'Douglas Gilbert',
'[email protected]' => 'David Woodhouse',
'[email protected]' => 'Ed L Cashin',
'[email protected]' => 'Felix Moeller',
'[email protected]' => 'Frank Zago',
'[email protected]' => 'Greg Kroah-Hartman',
'[email protected]' => 'Christoph Hellwig',
'[email protected]' => 'Tejun Heo',
'jejb@mulgrave.(none)' => 'James Bottomley',
'[email protected]' => 'James Bottomley',
'[email protected]' => 'Jeff Garzik',
'[email protected]' => 'Evgeniy Polyakov',
'[email protected]' => 'Kay Sievers',
'[email protected]' => 'Corey Minyard',
'[email protected]' => 'Mitesh shah',
'[email protected]' => 'Peter A Jonsson',
'[email protected]' => 'Rui Saraiva',
'[email protected]' => 'Santtu Hyrkkö',
'[email protected]' => 'Simon Kelley',
'[email protected]' => 'Sachin P Sant',
'[email protected]' => 'Morten Welinder',
'[email protected]' => 'Tony Luck',
'[email protected]' => 'Morten Welinder',
'[email protected]' => 'Morten Welinder',
'[email protected]' => 'Morten Welinder',
);
my (%map);
my $pstate = 1;
my $n_records = 0;
my $n_output = 0;
sub shortlog_entry($$) {
my ($name, $desc) = @_;
my $key = $name;
$desc =~ s#/pub/scm/linux/kernel/git/#/.../#g;
$desc =~ s#\[PATCH\] ##g;
# store description in array, in email->{desc list} map
if (exists $map{$key}) {
# grab ref
my $obj = $map{$key};
# add desc to array
push(@$obj, $desc);
} else {
# create new array, containing 1 item
my @arr = ($desc);
# store ref to array
$map{$key} = \@arr;
}
}
# sort comparison function
sub by_name($$) {
my ($a, $b) = @_;
uc($a) cmp uc($b);
}
sub shortlog_output {
my ($obj, $key, $desc);
foreach $key (sort by_name keys %map) {
# output author
printf "%s:\n", $key;
# output author's 1-line summaries
$obj = $map{$key};
foreach $desc (@$obj) {
print " $desc\n";
$n_output++;
}
# blank line separating author from next author
print "\n";
}
}
sub changelog_input {
my ($author, $desc);
while (<>) {
# get author and email
if ($pstate == 1) {
my ($email);
next unless /^Author: (.*)<(.*)>.*$/;
$n_records++;
$author = $1;
$email = $2;
$desc = undef;
# trim trailing whitespace.
# why doesn't chomp work?
while ($author && ($author =~ /\s$/)) {
chop $author;
}
# cset author fixups
if (exists $mailmap{$email}) {
$author = $mailmap{$email};
} elsif (exists $mailmap{$author}) {
$author = $mailmap{$author};
} elsif ((!$author) || ($author eq "")) {
$author = $email;
}
$pstate++;
}
# skip to blank line
elsif ($pstate == 2) {
next unless /^\s*$/;
$pstate++;
}
# skip to non-blank line
elsif ($pstate == 3) {
next unless /^\s*(\S.*)$/;
# skip lines that are obviously not
# a 1-line cset description
next if /^\s*From: /;
chomp;
$desc = $1;
&shortlog_entry($author, $desc);
$pstate = 1;
}
else {
die "invalid parse state $pstate";
}
}
}
sub finalize {
#print "\n$n_records records parsed.\n";
if ($n_records != $n_output) {
die "parse error: input records != output records\n";
}
}
&changelog_input;
&shortlog_output;
&finalize;
exit(0);