9 unless (defined $range) {
10 printf STDERR
"Usage: $0 range\n";
14 my $commit_url = 'https://git.lede-project.org/?p=source.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;
227 elsif ($line =~ m!^-\S+\s*:?=\s*([a-f0-9]{40})\b!)
231 elsif ($line =~ m!^\+\S+\s*:?=\s*([a-f0-9]{40})\b!)
236 if ($url && $old && $new)
238 return ($url, $old, $new);
250 sub find_weblink_template
($)
254 foreach my $rt (@weblinks)
256 my @m = $url =~ $rt->[0];
259 return sprintf $rt->[1], @m;
263 warn "No web link template for <$url>\n";
272 my $c = '<color #ccc>%s</color>';
273 my $g = '<color #282>%s</color>';
274 my $r = '<color #f00>%s</color>';
276 if ($commit->[7] > 1000)
278 $s .= sprintf $g, sprintf '+%.1fK', $commit->[7] / 1000;
280 elsif ($commit->[7] > 0)
282 $s .= sprintf $g, sprintf '+%d', $commit->[7];
285 if ($commit->[8] > 1000)
287 $s .= $s ?
sprintf($c, ',') : '';
288 $s .= sprintf $r, sprintf '-%.1fK', $commit->[8] / 1000;
290 elsif ($commit->[8] > 0)
292 $s .= $s ?
sprintf($c, ',') : '';
293 $s .= sprintf $r, sprintf '-%d', $commit->[8];
296 return sprintf($c, '(') . $s . sprintf($c, ')');
299 sub format_subject
($$)
301 my ($subject, $body) = @_;
303 if (length($subject) > 80)
305 $subject = substr($subject, 0, 77) . '...';
308 $subject =~ s!^([^\s:]+):\s*!</nowiki>**<nowiki>$1:</nowiki>** <nowiki>!g;
310 $subject = sprintf '<nowiki>%s</nowiki>', $subject;
311 $subject =~ s!<nowiki></nowiki>!!g;
320 printf "''[[%s|%s]]'' %s //%s//\\\\\n",
321 sprintf($commit_url, $change->[1]),
322 substr($change->[1], 0, 7),
323 format_subject
($change->[2], $change->[3]),
324 format_stat
($change);
329 foreach my $subchange (@
{$change->[6]})
333 printf " => ''[[%s|%s]]'' %s //%s//\\\\\n",
334 sprintf($change->[5], $subchange->[1]),
335 substr($subchange->[1], 0, 7),
336 format_subject
($subchange->[2], $subchange->[3]),
337 format_stat
($subchange);
341 printf " => ''%s'' %s //%s//\\\\\n",
342 substr($subchange->[1], 0, 7),
343 format_subject
($subchange->[2], $subchange->[3]),
344 format_stat
($subchange);
347 if (++$n > 15 && @
{$change->[6]} > $n)
349 printf " => + //%u more...//\\\\\n", @
{$change->[6]} - $n;
358 unless (-f
'/tmp/cveinfo.csv')
360 system('wget', '-O', '/tmp/cveinfo.csv.gz', 'https://cve.mitre.org/data/downloads/allitems.csv.gz') && return 0;
361 system('gunzip', '-f', '/tmp/cveinfo.csv.gz') && return 0;
369 my $csv = Text
::CSV
->new({ binary
=> 1 });
372 if (fetch_cve_info
() && $csv)
374 if (open CVE
, '<', '/tmp/cveinfo.csv')
376 while (defined(my $row = $csv->getline(*CVE
)))
378 foreach my $cve_id (@_)
380 if ($row->[0] eq $cve_id)
382 $cves{$cve_id} = [$row->[2], $row->[6]];
397 unless (-f
'/tmp/buginfo.csv')
399 system('wget', '-O', '/tmp/buginfo.csv', 'https://bugs.lede-project.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;
407 my $csv = Text
::CSV
->new({ binary
=> 1, allow_loose_quotes
=> 1, eol
=> "\012" });
410 if (fetch_bug_info
() && $csv)
412 if (open BUG
, '<', '/tmp/buginfo.csv')
414 while (defined(my $row = $csv->getline(*BUG
)))
416 foreach my $bug_id (@_)
418 if ($row->[0] eq $bug_id)
420 $bugs{$bug_id} = [$row->[4], $row->[5]];
436 my @commits = parse_history
('.', $range);
439 foreach my $commit (@commits)
441 my @topics = match_topics
(@
{$commit->[4]});
443 unless ($commit->[5])
445 my ($su, $so, $sn) = requires_subhistory
($commit->[2], $commit->[3], $commit->[1]);
447 $commit->[5] = find_weblink_template
($su);
448 $commit->[6] = fetch_subhistory
($su, $so, $sn);
452 foreach my $topic (@topics)
454 $topics{$topic} ||= [ ];
455 push @
{$topics{$topic}}, $commit;
458 my (%bug_ids, %cve_ids);
460 foreach my $bug ($commit->[2] =~ m!([A-Z]*#\d+)\b!g,
461 $commit->[3] =~ m!([A-Z]*#\d+)\b!g)
463 if ($bug =~ m!^(?:FS|GH|)#(\d+)$!)
469 foreach my $cve ($commit->[2] =~ m!\b(CVE-\d+-\d+|\d+-CVE-\d+)\b!g,
470 $commit->[3] =~ m!\b(CVE-\d+-\d+|\d+-CVE-\d+)\b!g)
472 # fix misspelled CVE IDs
473 $cve =~ s!^(\d+)-CVE-!CVE-$1-!;
477 foreach my $bug (keys %bug_ids)
480 push @
{$bugs{$bug}}, $commit;
483 foreach my $cve (keys %cve_ids)
486 push @
{$cves{$cve}}, $commit;
491 my @topics = sort { (($a eq 'Miscellaneous') <=> ($b eq 'Miscellaneous')) || $a cmp $b } keys %topics;
493 foreach my $topic (@topics)
495 my @commits = grep { !$reverts{$_->[1]} } @
{$topics{$topic}};
497 printf "==== %s (%d change%s) ====\n", $topic, 0 + @commits, @commits > 1 ?
's' : '';
499 foreach my $change (sort { $a->[0] <=> $b->[0] } @commits)
501 format_change
($change);
507 my @bugs = sort { int($a) <=> int($b) } keys %bugs;
508 my $bug_info = parse_bugs
(@bugs);
510 @bugs = grep { $bug_info->{$_} && $bug_info->{$_}[0] } @bugs;
514 printf "===== Addressed bugs =====\n";
516 foreach my $bug (@bugs)
518 printf "=== #%s ===\n", $bug;
519 printf "**Description:** <nowiki>%s</nowiki>\\\\\n", $bug_info->{$bug}[0];
520 printf "**Link:** [[https://bugs.lede-project.org/index.php?do=details&task_id=%s]]\\\\\n", $bug;
521 printf "**Commits:**\\\\\n";
523 foreach my $commit (@
{$bugs{$bug}})
525 format_change
($commit);
536 sort { ($a->[0] <=> $b->[0]) || ($a->[1] cmp $b->[1]) }
537 map { $_ =~ m!^CVE-(\d+)-(\d+)$! ?
[ $1 * 10000000 + $2, $_ ] : [ 0, $_ ] }
540 my $cve_info = parse_cves
(@cves);
544 printf "===== Security fixes ====\n";
546 foreach my $cve (@cves)
548 printf "=== %s ===\n", $cve;
550 if ($cve_info->{$cve} && $cve_info->{$cve}[0])
552 printf "**Description:** <nowiki>%s</nowiki>\n\n", $cve_info->{$cve}[0];
555 printf "**Link:** [[https://cve.mitre.org/cgi-bin/cvename.cgi?name=%s]]\\\\\n", $cve;
556 printf "**Commits:**\\\\\n";
558 foreach my $commit (@
{$cves{$cve}})
560 format_change
($commit);