9 unless (defined $range) {
10 printf STDERR
"Usage: $0 range\n";
14 my $commit_url = 'https://git.openwrt.org/?p=openwrt/openwrt.git;a=commitdiff;h=%s';
17 [ qr
'^[^:]+://(git.lede-project.org/)(.+)$' => 'https://%s?p=%s;a=commitdiff;h=%%s' ],
18 [ qr
'^[^:]+://(git.openwrt.org/)(.+)$' => 'https://%s?p=%s;a=commitdiff;h=%%s' ],
19 [ qr
'^[^:]+://(github.com/.+?)(?:\.git)?$' => 'https://%s/commit/%%s' ],
20 [ qr
'^[^:]+://git.kernel.org/pub/scm/(.+)$' => 'https://git.kernel.org/cgit/%s/commit/?id=%%s' ],
21 [ qr
'^[^:]+://w1.fi/(?:.+/)?(.+)\.git$' => 'https://w1.fi/cgit/%s/commit/?id=%%s' ],
32 my ($fh, $default) = @_;
34 my $line = readline $fh;
46 [ qr
'^package/(kernel)/linux', 'Kernel' ],
47 [ qr
'^(target/linux/generic|include/kernel-version.mk)', 'Kernel' ],
48 [ qr
'^package/kernel/(mac80211)', 'Wireless / Common' ],
49 [ qr
'^package/kernel/(ath10k-ct)', 'Wireless / Ath10k CT' ],
50 [ qr
'^package/kernel/(mt76)', 'Wireless / MT76' ],
51 [ qr
'^package/(base-files)/', 'Packages / LEDE base files' ],
52 [ qr
'^package/(boot)/', 'Packages / Boot Loaders' ],
53 [ qr
'^package/firmware/', 'Packages / Firmware' ],
54 [ qr
'^package/.+/(uhttpd|usbmode|jsonfilter|ugps|libubox|procd|mountd|ubus|uci|usign|rpcd|fstools|ubox)/', 'Packages / LEDE system userland' ],
55 [ qr
'^package/.+/(iwinfo|umbim|uqmi|relayd|mdns|firewall|netifd|uclient|ustream-ssl|gre|ipip|qos-scripts|swconfig|vti|6in4|6rd|6to4|ds-lite|map|odhcp6c|odhcpd)/', 'Packages / LEDE network userland' ],
56 [ qr
'^package/[^/]+/([^/]+)', 'Packages / Common' ],
57 [ qr
'^target/sdk/', 'Build System / SDK' ],
58 [ qr
'^target/imagebuilder/', 'Build System / Image Builder' ],
59 [ qr
'^target/toolchain/', 'Build System / Toolchain' ],
60 [ qr
'^target/linux/([^/]+)', 'Target / $1' ],
61 [ qr
'^(tools)/[^/]+', 'Build System / Host Utilities' ],
62 [ qr
'^(toolchain)/[^/]+', 'Build System / Toolchain' ],
63 [ qr
'^(config/|include/|scripts/|target/[^/]+$|Makefile|rules\.mk)', 'Build System / Buildroot' ],
64 [ qr
'^(feeds)\b', 'Build System / Feeds' ],
67 my @subhistory_matches = (
68 qr
'(?i)^\S+: update to\b',
69 qr
'(?i)^\S+: Upstep to\b',
70 qr
'(?i)^\S+: bump to\b',
72 qr
'(?i)^\S+: backport\b',
73 qr
'(?i)\blatest HEAD\b',
82 foreach my $rs (@topic_paths)
84 if ($path =~ $rs->[0])
97 my @topics = sort keys %topics;
98 return (@topics > 0 ?
@topics : ('Miscellaneous'));
101 sub parse_history
($$)
103 my ($dir, $range) = @_;
106 my ($max_add, $total_add, $max_del, $total_del) = (0, 0, 0, 0);
108 if (open GIT
, '-|', 'git', "--git-dir=$dir/.git", 'log', '--format=@@%n%H%n%s%n%b%n@@', '--numstat', '--reverse', '--no-merges', $range)
115 my $hash = line
(GIT
, '');
116 my $subject = line
(GIT
, '');
118 last unless (length($subject) && $hash =~ m!^!);
123 my ($add, $del) = (0, 0);
125 my $is_revert = $subject =~ m!^Revert !;
127 $reverts{$hash}++ if $is_revert;
129 while ($line ne '@@')
131 $body .= length($line) ?
"$line\n" : '';
132 $line = line
(*GIT
, '@@');
134 if ($is_revert && $line =~ m!\b([0-9a-f]{40})\b!)
142 while ($line ne '@@')
144 if ($line =~ m!^(\d+|-)\s+(\d+|-)\s+(.+)$!)
146 $add += ($1 eq '-') ?
0 : int($1);
147 $del += ($2 eq '-') ?
0 : int($2);
151 $line = line
(*GIT
, '@@');
169 $max_add = ($add > $max_add) ?
$add : $max_add;
170 $max_del = ($del > $max_del) ?
$del : $max_del;
172 push @commits, $commit;
178 if (@commits > 0 && $commits[0][2] =~ /\brevert to branch defaults$/)
183 return wantarray ?
@commits : \
@commits;
186 sub fetch_subhistory
($$$)
188 my ($url, $old, $new) = @_;
190 (my $path = $url) =~ s![^a-z0-9_-]+!-!g;
192 unless (-d
"/tmp/repos/$path")
195 system('git', 'clone', '--quiet', $url, "/tmp/repos/$path");
199 system('git', "--work-tree=/tmp/repos/$path", "--git-dir=/tmp/repos/$path/.git", 'pull', '--quiet');
202 return parse_history
("/tmp/repos/$path", "$old..$new");
205 sub requires_subhistory
($$$)
207 my ($subject, $body, $hash) = @_;
209 foreach my $re (@subhistory_matches)
211 if ($subject =~ $re || $body =~ $re)
213 if (open DIFF
, '-|', 'git', 'diff', "$hash^!")
215 my ($url, $old, $new);
217 while (defined(my $line = readline DIFF
))
221 if ($line =~ m!^[ +]PKG_SOURCE_URL\s*:?=\s*(\S+)!)
224 $url =~ s!\$\(LEDE_GIT\)!https://git.lede-project.org!g;
225 $url =~ s!\$\(OPENWRT_GIT\)!https://git.openwrt.org!g;
226 $url =~ s!\$\(PROJECT_GIT\)!https://git.openwrt.org!g;
228 elsif ($line =~ m!^-\S+\s*:?=\s*([a-f0-9]{40})\b!)
232 elsif ($line =~ m!^\+\S+\s*:?=\s*([a-f0-9]{40})\b!)
237 if ($url && $old && $new)
239 return ($url, $old, $new);
251 sub find_weblink_template
($)
255 foreach my $rt (@weblinks)
257 my @m = $url =~ $rt->[0];
260 return sprintf $rt->[1], @m;
264 warn "No web link template for <$url>\n";
273 my $c = '<color #ccc>%s</color>';
274 my $g = '<color #282>%s</color>';
275 my $r = '<color #f00>%s</color>';
277 if ($commit->[7] > 1000)
279 $s .= sprintf $g, sprintf '+%.1fK', $commit->[7] / 1000;
281 elsif ($commit->[7] > 0)
283 $s .= sprintf $g, sprintf '+%d', $commit->[7];
286 if ($commit->[8] > 1000)
288 $s .= $s ?
sprintf($c, ',') : '';
289 $s .= sprintf $r, sprintf '-%.1fK', $commit->[8] / 1000;
291 elsif ($commit->[8] > 0)
293 $s .= $s ?
sprintf($c, ',') : '';
294 $s .= sprintf $r, sprintf '-%d', $commit->[8];
297 return sprintf($c, '(') . $s . sprintf($c, ')');
300 sub format_subject
($$)
302 my ($subject, $body) = @_;
304 if (length($subject) > 80)
306 $subject = substr($subject, 0, 77) . '...';
309 $subject =~ s!^([^\s:]+):\s*!</nowiki>**<nowiki>$1:</nowiki>** <nowiki>!g;
311 $subject = sprintf '<nowiki>%s</nowiki>', $subject;
312 $subject =~ s!<nowiki></nowiki>!!g;
321 printf "''[[%s|%s]]'' %s //%s//\\\\\n",
322 sprintf($commit_url, $change->[1]),
323 substr($change->[1], 0, 7),
324 format_subject
($change->[2], $change->[3]),
325 format_stat
($change);
330 foreach my $subchange (@
{$change->[6]})
334 printf " => ''[[%s|%s]]'' %s //%s//\\\\\n",
335 sprintf($change->[5], $subchange->[1]),
336 substr($subchange->[1], 0, 7),
337 format_subject
($subchange->[2], $subchange->[3]),
338 format_stat
($subchange);
342 printf " => ''%s'' %s //%s//\\\\\n",
343 substr($subchange->[1], 0, 7),
344 format_subject
($subchange->[2], $subchange->[3]),
345 format_stat
($subchange);
348 if (++$n > 15 && @
{$change->[6]} > $n)
350 printf " => + //%u more...//\\\\\n", @
{$change->[6]} - $n;
359 unless (-f
'/tmp/cveinfo.csv')
361 system('wget', '-O', '/tmp/cveinfo.csv.gz', 'https://cve.mitre.org/data/downloads/allitems.csv.gz') && return 0;
362 system('gunzip', '-f', '/tmp/cveinfo.csv.gz') && return 0;
370 my $csv = Text
::CSV
->new({ binary
=> 1 });
373 if (fetch_cve_info
() && $csv)
375 if (open CVE
, '<', '/tmp/cveinfo.csv')
377 while (defined(my $row = $csv->getline(*CVE
)))
379 foreach my $cve_id (@_)
381 if ($row->[0] eq $cve_id)
383 $cves{$cve_id} = [$row->[2], $row->[6]];
398 unless (-f
'/tmp/buginfo.csv')
400 system('wget', '-O', '/tmp/buginfo.csv', 'https://bugs.openwrt.org/index.php?string=&project=2&do=index&export_list=Export+Tasklist&advancedsearch=on&type%5B%5D=&sev%5B%5D=&pri%5B%5D=&due%5B%5D=&reported%5B%5D=&cat%5B%5D=&status%5B%5D=&percent%5B%5D=&opened=&dev=&closed=&duedatefrom=&duedateto=&changedfrom=&changedto=&openedfrom=&openedto=&closedfrom=&closedto=') && return 0;
408 my $csv = Text
::CSV
->new({ binary
=> 1, allow_loose_quotes
=> 1, eol
=> "\012" });
411 if (fetch_bug_info
() && $csv)
413 if (open BUG
, '<', '/tmp/buginfo.csv')
415 while (defined(my $row = $csv->getline(*BUG
)))
417 foreach my $bug_id (@_)
419 if ($row->[0] eq $bug_id)
421 $bugs{$bug_id} = [$row->[4], $row->[5]];
437 my @commits = parse_history
('.', $range);
440 foreach my $commit (@commits)
442 my @topics = match_topics
(@
{$commit->[4]});
444 unless ($commit->[5])
446 my ($su, $so, $sn) = requires_subhistory
($commit->[2], $commit->[3], $commit->[1]);
448 $commit->[5] = find_weblink_template
($su);
449 $commit->[6] = fetch_subhistory
($su, $so, $sn);
453 foreach my $topic (@topics)
455 $topics{$topic} ||= [ ];
456 push @
{$topics{$topic}}, $commit;
459 my (%bug_ids, %cve_ids);
461 foreach my $bug ($commit->[2] =~ m!([A-Z]*#\d+)\b!g,
462 $commit->[3] =~ m!([A-Z]*#\d+)\b!g)
464 if ($bug =~ m!^(?:FS|GH|)#(\d+)$!)
470 foreach my $cve ($commit->[2] =~ m!\b(CVE-\d+-\d+|\d+-CVE-\d+)\b!g,
471 $commit->[3] =~ m!\b(CVE-\d+-\d+|\d+-CVE-\d+)\b!g)
473 # fix misspelled CVE IDs
474 $cve =~ s!^(\d+)-CVE-!CVE-$1-!;
478 foreach my $bug (keys %bug_ids)
481 push @
{$bugs{$bug}}, $commit;
484 foreach my $cve (keys %cve_ids)
487 push @
{$cves{$cve}}, $commit;
492 my @topics = sort { (($a eq 'Miscellaneous') <=> ($b eq 'Miscellaneous')) || $a cmp $b } keys %topics;
494 foreach my $topic (@topics)
496 my @commits = grep { !$reverts{$_->[1]} } @
{$topics{$topic}};
498 printf "==== %s (%d change%s) ====\n", $topic, 0 + @commits, @commits > 1 ?
's' : '';
500 foreach my $change (sort { $a->[0] <=> $b->[0] } @commits)
502 format_change
($change);
508 my @bugs = sort { int($a) <=> int($b) } keys %bugs;
509 my $bug_info = parse_bugs
(@bugs);
511 @bugs = grep { $bug_info->{$_} && $bug_info->{$_}[0] } @bugs;
515 printf "===== Addressed bugs =====\n";
517 foreach my $bug (@bugs)
519 printf "=== #%s ===\n", $bug;
520 printf "**Description:** <nowiki>%s</nowiki>\\\\\n", $bug_info->{$bug}[0];
521 printf "**Link:** [[https://bugs.openwrt.org/index.php?do=details&task_id=%s]]\\\\\n", $bug;
522 printf "**Commits:**\\\\\n";
524 foreach my $commit (@
{$bugs{$bug}})
526 format_change
($commit);
537 sort { ($a->[0] <=> $b->[0]) || ($a->[1] cmp $b->[1]) }
538 map { $_ =~ m!^CVE-(\d+)-(\d+)$! ?
[ $1 * 10000000 + $2, $_ ] : [ 0, $_ ] }
541 my $cve_info = parse_cves
(@cves);
545 printf "===== Security fixes ====\n";
547 foreach my $cve (@cves)
549 printf "=== %s ===\n", $cve;
551 if ($cve_info->{$cve} && $cve_info->{$cve}[0])
553 printf "**Description:** <nowiki>%s</nowiki>\n\n", $cve_info->{$cve}[0];
556 printf "**Link:** [[https://cve.mitre.org/cgi-bin/cvename.cgi?name=%s]]\\\\\n", $cve;
557 printf "**Commits:**\\\\\n";
559 foreach my $commit (@
{$cves{$cve}})
561 format_change
($commit);