#!/usr/bin/perl -w
use strict;
if ($#ARGV != 1) {
print "Usage: $0 suse_machine git_range\n";
exit 1;
}
my $machine = $ARGV[0];
my $range = $ARGV[1];
my $idsfile = "/dev/shm/ids";
my $patchfile = "/dev/shm/patch";
my $user = 'Jiri Slaby <jslaby@suse.cz>';
my $new_version = "";
if ($range =~ /^v(2\.6\.[0-9]+(\.[0-9]+)?)\.\.v(2\.6\.[0-9]+\.([0-9]+))$/ ||
$range =~ /^v(3\.[0-9]+(\.[0-9]+)?)\.\.v(3\.[0-9]+\.([0-9]+))$/) {
$new_version = $3;
$patchfile .= "-";
if (defined $2) {
$patchfile .= "$1-$4";
} else {
$patchfile .= $3;
}
}
open GIT, "git log --format=%B $range|" ||
die "git log cannot be run";
open OUT, "|ssh -C $machine -o StrictHostKeyChecking=no 'cat >$idsfile'" ||
die "ssh didn't start";
my @SHAs;
my $cont = 0;
while (<GIT>) {
if ($cont) {
if (/^\s+([0-9a-f]{40})\s*[\])]$/) {
print OUT "$1\n";
push @SHAs, $1;
$cont = 0;
next;
}
}
if (/^commit ([0-9a-f]{40}) upstream\.?$/ ||
/^[\[(]\s*[Uu]pstream commit ([0-9a-f]{40})\s*[\])]$/ ||
/^[uU]pstream commit ([0-9a-f]{40})\.$/ ||
/^This is a backport of ([0-9a-f]{40})$/ ||
/^\(cherry picked from commit ([0-9a-f]{40})\)$/) {
print OUT "$1\n";
push @SHAs, $1;
} elsif (/^[\[(]\s*[Uu]pstream commits ([0-9a-f]{40})\s+and\s*$/) {
print OUT "$1\n";
push @SHAs, $1;
$cont = 1;
} elsif (/\b[0-9a-f]{40}\b/) {
print "\tUnmatched SHA: $_";
}
}
close OUT;
close GIT;
print "Written $idsfile on $machine\n";
open GIT, "git diff $range|" ||
die "git diff cannot be run";
open OUT, "|ssh -C $machine 'cat >$patchfile'" ||
die "ssh didn't start";
print OUT "From: $user\n";
print OUT "Subject: Linux $new_version\n";
print OUT "Patch-mainline: $new_version\n";
foreach (@SHAs) {
print OUT "Git-commit: $_\n";
}
print OUT "\n";
print OUT "Signed-off-by: $user\n";
print OUT "---\n";
while (<GIT>) {
print OUT;
}
close OUT;
close GIT;
print "Written $patchfile on $machine\n";
0;