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
|
#!/usr/bin/perl -w
use English;
use File::Basename;
use strict;
## Given a patch file paths on the command line,
## e.g. debian/patches/*.patch (or quilt series), generate blank-line
## separate entries formated for README.Debian. If a patch file
## doesn't contain a "README-Debian:" pseudo-header, then just include
## the entire commit message. If it does include the header, then
## parse it roughly like a debian/control "Description:" field. In
## particular, any blank line ends the header, continuation lines must
## start with a single space, and blank lines can be included in the
## content via lines contining just a space and a full stop ".".
## Currently, there is also no reformatting, so all lines are
## "verbatim", not just lines starting with a double space.
sub get_patch_readme
{
my ($patch) = @_;
open(PATCH, '<', $patch) or die "Unable to open $patch: $!";
my @header = <PATCH>;
close PATCH;
chomp @header;
my @result;
my $in_header = 0;
foreach my $line (@header) {
last if $line eq '---';
if ($line =~ m/^README-Debian:\s*(.*)/gio) {
push @result, $1;
$in_header = 1;
} elsif ($line =~ m/^\S*$/o) {
$in_header = 0;
} elsif ($in_header) {
if ($line eq ' .') {
push @result, '';
} elsif (substr($line, 0, 2) eq ' .') {
die "Invalid ' .' prefix in line: '$line'";
} elsif ($line =~ m/^ (.*)/o) {
push @result, $1;
} else {
$in_header = 0;
}
}
}
if (!scalar(@result)) {
# No README-Debian, include the whole message
my $i = 0;
my $subject;
foreach my $line (@header) {
if ($line =~ m/^Subject:\s*(.*)/io) {
$subject = $1;
}
$i++;
last if $line eq '';
}
die 'No subject in patch' unless $subject;
push @result, $subject;
while ($i < scalar(@header)) {
last if $header[$i] eq '---';
push @result, $header[$i];
$i++;
}
}
# Remove trailing blank lines
while ($result[-1] eq '') { pop @result; }
return \@result;
}
sub render_patch_readme
{
my ($patch) = @_;
my $news = get_patch_readme($patch);
my $base = basename($patch);
print "* @$news[0]\n";
my $news_len = scalar(@$news);
foreach my $line (@$news[1..$news_len - 1]) {
print "$line\n";
}
print "\n" if scalar(@$news) > 1;
print "Patch: $base\n";
}
my @patches = @ARGV;
my $patch_count = @patches;
if ($patch_count)
{
render_patch_readme($patches[0]);
foreach my $patch (@patches[1..$patch_count - 1])
{
print "\n";
render_patch_readme($patch);
}
}
|