OLD | NEW |
(Empty) | |
| 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->{'commi
t'} . |
| 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 $bug = undef; |
| 172 my %bugz = (); |
| 173 my $k; |
| 174 |
| 175 # skip lines that are obviously not |
| 176 # a 1-line cset description |
| 177 next if /^\s*From: /; |
| 178 |
| 179 chomp; |
| 180 $desc = $1; |
| 181 |
| 182 if ($desc =~ /^ *(Revert "|)UBUNTU:/) { |
| 183 while (<STDIN>) { |
| 184 $ignore = 1 if /^ *Ignore: yes/i; |
| 185 if (/^ *Bug: *(#|)(.*)/i) { |
| 186 foreach $k (split('(,|)*\s*#', $
2)) { |
| 187 $bugz{$k} = 1 if (($k ne
'') and ($k =~ /[0-9]+/)); |
| 188 } |
| 189 } |
| 190 elsif (/^ *BugLink: *http.*:\/\/.*\/([0-
9]+)/i) { |
| 191 $bugz{$1} = 1; |
| 192 } |
| 193 elsif (/^ *(CVE-.*)/) { |
| 194 $cve = $1 |
| 195 } |
| 196 last if /^commit /; |
| 197 } |
| 198 } else { |
| 199 $author = $kernel_auth; |
| 200 $ignore = 1 if $desc =~ /Merge /; |
| 201 while (<STDIN>) { |
| 202 if (/^ *Bug: *(#|)(.*)/i) { |
| 203 foreach $k (split('(,|)*\s*#', $
2)) { |
| 204 $bugz{$k} = 1 if (($k ne
'') and ($k =~ /[0-9]+/)); |
| 205 } |
| 206 } |
| 207 elsif (/^ *BugLink: *http.*:\/\/.*\/([0-
9]+)/i) { |
| 208 $bugz{$1} = 1; |
| 209 } |
| 210 elsif (/^ *(CVE-.*)/) { |
| 211 $cve = $1 |
| 212 } |
| 213 last if /^commit /; |
| 214 } |
| 215 } |
| 216 |
| 217 $bug = join(", #", keys(%bugz)); |
| 218 if (!$ignore) { |
| 219 &shortlog_entry($author, $desc, $bug, |
| 220 $cve, $commit, 0); |
| 221 } |
| 222 |
| 223 $pstate = 1; |
| 224 if ($_ && /^commit (.*)/) { |
| 225 $commit = $1; |
| 226 $pstate++; |
| 227 } |
| 228 } |
| 229 |
| 230 else { |
| 231 die "invalid parse state $pstate"; |
| 232 } |
| 233 } |
| 234 |
| 235 foreach $entry (@reverts) { |
| 236 add_entry($entry); |
| 237 } |
| 238 } |
| 239 |
| 240 &changelog_input; |
| 241 &shortlog_output; |
| 242 |
| 243 exit(0); |
OLD | NEW |