blob: 7cc902ed77ab075b0fb52b3a9c9f5020561484d1 [file] [log] [blame]
#!/usr/bin/perl -W
#
# This takes a mbox of email, created with 'quilt mail --mbox'
# and formats it in the proper way to send off a -stable kernel review.
#
# This means:
# - strip off some quilt headers and the threading
# - add some text at the top of every message.
#
# Written in perl because the bash version is broken, it doesn't pass
# through the patch correctly :(
#
my $line;
my $root_version = shift;
if ($root_version eq "") {
print "must provide kernel root version number\n";
die;
}
my $full_version = shift;
if ($full_version eq "") {
print "must provide kernel full version number\n";
die;
}
my $mbox = shift;
if ($mbox eq "") {
print "must provide the name of the mbox file\n";
die;
}
my $major_version = substr($root_version, 0, 1);
my $date=`date -u --iso-8601=minutes --date="2 days"`;
chomp($date);
$mboxnew = "$mbox.new";
chomp($mboxnew);
open MBOX, "$mbox" || die "Failed to open $mbox";
open FILE, ">$mboxnew" || die "Failed to create $mboxnew";
my $header = "true";
my $eat = "false";
my $tags_written = "false";
my $stable_tag_written = "false";
while ($line = <MBOX>) {
$eat = "false";
if ($header eq "false") {
if ($line =~ m/^From /) {
# start of a message, this is the header
$header = "true";
}
}
if ($header eq "true") {
if ($stable_tag_written eq "false") {
if ($line =~ m/^Subject:/) {
# always add a "X-stable: review" tag
print FILE "X-stable: review\n";
$stable_tag_written = "true";
# and a "X-Patchwork-Hint: ignore" tag
print FILE "X-Patchwork-Hint: ignore\n"
}
}
# if first Subject: line, add our tags
if ($tags_written eq "false") {
if ($line =~ m/^Subject:/) {
# write out our own X-KernelTest tags to make automated tools's lives easier
print FILE "X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v$major_version.x/stable-review/patch-$full_version.gz\n";
print FILE "X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git\n";
print FILE "X-KernelTest-Branch: linux-$root_version.y\n";
print FILE "X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git\n";
print FILE "X-KernelTest-Version: $full_version\n";
print FILE "X-KernelTest-Deadline: $date\n";
$tags_written = "true";
# hack around the fact that content-type is not in the 000 message
# and so the 001 message will not get the X- flags we want to set above
$stable_tag_written = "false";
}
}
# strip out References line
if ($line =~ m/^References:/) {
# eat the line
$eat = "true";
}
# strip out the Content-Disposition line
if ($line =~ m/Content-Disposition:/) {
# eat the line
$eat = "true";
# we are now out of the header
$header = "false";
$stable_tag_written = "false";
# write out our custom header too
print FILE "\n";
print FILE "$root_version-stable review patch. If anyone has any objections, please let me know.\n";
print FILE "\n";
print FILE "------------------\n";
}
}
if ($eat eq "false") {
print FILE $line;
}
}
close MBOX;
close FILE;
#print "# New mailbox is in $mboxnew\n";
#print "# To send the patches out, do:\n";
#print "cat $mboxnew | formail -A \"In-Reply-To: <FOO>\" -s msmtp-enqueue.sh\n";
#print "# or\n";
#print "< $mboxnew formail -ds sh -c 'cat > msg.\$FILENO'\n";