]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - debian/scripts/misc/git-ubuntu-log
2967d875bd64b8ef660eace07186674955139f04
[mirror_ubuntu-zesty-kernel.git] / debian / scripts / misc / git-ubuntu-log
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Text::Wrap;
5
6 my $kernel_auth = "Upstream Kernel Changes";
7
8 my (%map, @reverts);
9 my $pstate = 1;
10 my $no_kern_log = 0;
11 my $print_shas = 0;
12 my $first_print = 1;
13
14 while (@ARGV) {
15 my $opt = $ARGV[0];
16 shift;
17 if ($opt eq "--no-kern-log") {
18 $no_kern_log = 1;
19 } elsif ($opt eq "--print-shas") {
20 $print_shas = 1;
21 } else {
22 print STDERR "Unknown options: $opt\n";
23 exit(1);
24 }
25 }
26
27 sub check_reverts($) {
28 my ($entry) = @_;
29 my ($check);
30
31 foreach $check (reverse @reverts) {
32 my $desc = "Revert \"" . $entry->{'desc'} . "\"";
33 if ($check->{'desc'} eq $desc) {
34 @reverts = grep($_->{'desc'} ne $desc, @reverts);
35 return 1;
36 }
37 }
38
39 return 0;
40 }
41
42 sub add_entry($) {
43 my ($entry) = @_;
44 my $key = $entry->{'author'};
45
46 # store description in array, in email->{desc list} map
47 if (exists $map{$key}) {
48 # grab ref
49 my $obj = $map{$key};
50
51 # add desc to array
52 push(@$obj, $entry);
53 } else {
54 # create new array, containing 1 item
55 my @arr = ($entry);
56
57 # store ref to array
58 $map{$key} = \@arr;
59 }
60 }
61
62 sub shortlog_entry($$$$$) {
63 my ($name, $desc, $bug, $cve, $commit) = @_;
64 my $entry;
65
66 $desc =~ s#/pub/scm/linux/kernel/git/#/.../#g;
67 $desc =~ s#\[PATCH\] ##g;
68
69 $desc =~ s#^\s*##g;
70 $desc =~ s# *UBUNTU: ##g;
71
72 $entry->{'desc'} = $desc;
73 if ($bug ne '') {
74 $entry->{'bugno'} = $bug;
75 }
76 $entry->{'cve'} = $cve;
77 $entry->{'commit'} = $commit;
78 $entry->{'author'} = $name;
79
80 if ($desc =~ /^Revert "/) {
81 push(@reverts, $entry);
82 return;
83 }
84
85 return if check_reverts($entry);
86
87 add_entry($entry);
88 }
89
90 # sort comparison function
91 sub by_name($$) {
92 my ($a, $b) = @_;
93
94 uc($a) cmp uc($b);
95 }
96
97 sub shortlog_output {
98 my ($obj, $key, $entry);
99
100 foreach $key (sort by_name keys %map) {
101 next if $key eq $kernel_auth and $no_kern_log;
102
103 print "\n" unless $first_print;
104 $first_print = 0;
105
106 # output author
107 printf " [ %s ]\n\n", $key;
108
109 # output author's 1-line summaries
110 $obj = $map{$key};
111 foreach $entry (reverse @$obj) {
112 print wrap(" * ", " ", $entry->{'desc'}) . "\n";
113 # For non upstream changes, add other info.
114 if ($key ne $kernel_auth) {
115 if ($print_shas) {
116 print " - GIT-SHA " . $entry->{'commit'} .
117 "\n";
118 }
119 }
120 if (defined($entry->{'bugno'})) {
121 print " - LP: #" . $entry->{'bugno'} . "\n";
122 }
123 if (defined($entry->{'cve'})) {
124 print " - " . $entry->{'cve'} . "\n";
125 }
126 }
127 }
128 }
129
130 sub changelog_input {
131 my ($author, $desc, $commit, $entry, $cve);
132
133 while (<STDIN>) {
134 # get commit
135 if ($pstate == 1) {
136 next unless /^commit (.*)/;
137
138 $commit = $1;
139
140 $pstate++;
141 }
142
143 # get author and email
144 elsif ($pstate == 2) {
145 my ($email);
146
147 next unless /^[Aa]uthor:?\s*(.*?)\s*<(.*)>/;
148
149 $author = $1;
150 $email = $2;
151 $desc = undef;
152 $cve = undef;
153
154 # cset author fixups
155 if (!$author) {
156 $author = $email;
157 }
158 $pstate++;
159 }
160
161 # skip to blank line
162 elsif ($pstate == 3) {
163 next unless /^\s*$/;
164 $pstate++;
165 }
166
167 # skip to non-blank line
168 elsif ($pstate == 4) {
169 next unless /^\s*?(.*)/;
170 my $ignore = 0;
171 my $do_ignore = 0;
172 my $bug = undef;
173 my %bugz = ();
174 my $k;
175
176 # skip lines that are obviously not
177 # a 1-line cset description
178 next if /^\s*From: /;
179
180 chomp;
181 $desc = $1;
182
183 if ($desc =~ /^ *(Revert "|)UBUNTU:/) {
184 $do_ignore = 1;
185 } else {
186 $do_ignore = 0;
187 $author = $kernel_auth;
188 $ignore = 1 if $desc =~ /Merge /;
189 }
190 while (<STDIN>) {
191 $ignore = 1 if ($do_ignore && /^ *Ignore: yes/i);
192 if (/^ *Bug: *(#|)([0-9#,\s]*)\s*$/i) {
193 foreach $k (split('(,|\s)\s*(#|)', $2)) {
194 $bugz{$k} = 1 if (($k ne '') and ($k =~ /[0-9]+/));
195 }
196 }
197 elsif (/^ *BugLink: *http.*:\/\/.*\/([0-9]+)/i) {
198 $bugz{$1} = 1;
199 }
200 elsif (/^ *(CVE-.*)/) {
201 $cve = $1
202 }
203 last if /^commit /;
204 }
205
206 $bug = join(", #", sort keys(%bugz));
207 if (!$ignore) {
208 &shortlog_entry($author, $desc, $bug,
209 $cve, $commit, 0);
210 }
211
212 $pstate = 1;
213 if ($_ && /^commit (.*)/) {
214 $commit = $1;
215 $pstate++;
216 }
217 }
218
219 else {
220 die "invalid parse state $pstate";
221 }
222 }
223
224 foreach $entry (@reverts) {
225 add_entry($entry);
226 }
227 }
228
229 &changelog_input;
230 &shortlog_output;
231
232 exit(0);