Blob Blame History Raw
#!/usr/bin/perl -w
use strict;

if (@ARGV < 2) {
	print "Usage: $0 suse_machine stable_version [user_id]\n";
	exit 1;
}

my $machine = shift;
my $stable_ver = shift;
my $idsfile = "/dev/shm/ids";
my $patchfile = "/dev/shm/patch-";
my $user = 'Jiri Slaby <jslaby@suse.cz>';
my $old_version;
my $new_version;

if (@ARGV > 0) {
	$user = join(' ', @ARGV);
}

my %bnc_map = (
	'3.12' => '1012620',
	'4.1' => '1023711',
	'4.4' => '1012382',
	'other' => '1012628',
);
my $bnc;

if ($stable_ver =~ /^v?((2\.6\.[0-9]+)\.([0-9]+))$/ ||
    $stable_ver =~ /^v?(([3-9]\.[0-9]+)\.([0-9]+))$/) {
	$new_version = $1;
	$old_version = $2;
	$bnc = $bnc_map{$old_version};
	if ($3 eq 1) {
		$patchfile .= $new_version;
	} else {
		$old_version .= '.' . ($3 - 1);
		$patchfile .= "$old_version-$3";
	}
} else {
	die "cannot understand stable version $stable_ver";
}

if (!defined $bnc) {
	print "Kernel version not found in the map, assuming Tumbleweed\n";
	$bnc = $bnc_map{'other'};
}

my $range = "v$old_version..v$new_version";

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 --no-renames $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 "References: bnc#$bnc\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;