Roland McGrath 11487c5
#!/usr/bin/perl -w
Roland McGrath 11487c5
#
Roland McGrath 11487c5
# Script to rediff all patches in the spec
Roland McGrath 11487c5
# Usage: perl -w rediffall.pl < kernel-2.4.spec
Roland McGrath 11487c5
#
Roland McGrath 11487c5
# $workdir is where the new rediff'ed patches are created
Roland McGrath 11487c5
# $origdir is where the original patches and tarball are located
Roland McGrath 11487c5
#
Roland McGrath 11487c5
# Note that both $workdir and $origdir must be absolute path names.
Roland McGrath 11487c5
# Suggestion: create a /kernel symbolic link to the top of your CVS tree.
Roland McGrath 11487c5
Roland McGrath 11487c5
my $workdir = "/dev/shm/redifftree";
Roland McGrath 11487c5
my $origdir = "/home/davej/devel";
Roland McGrath 11487c5
my $kernver = "linux-2.6.17";
Roland McGrath 11487c5
my $datestrip = "s/^\\(\\(+++\\|---\\) [^[:blank:]]\\+\\)[[:blank:]].*/\\1/";
Roland McGrath 11487c5
my $patchindex = 0;
Roland McGrath 11487c5
my @patchlist;
Roland McGrath 11487c5
Roland McGrath 11487c5
# phase 1: create a tree
Roland McGrath 11487c5
print "Extracting pristine source..\n";
Roland McGrath 11487c5
system("mkdir -p $workdir");
Roland McGrath 11487c5
system("rm -rf $workdir/*");
Roland McGrath 11487c5
chdir("$workdir");
Roland McGrath 11487c5
system("tar -jxvf $origdir/$kernver.tar.bz2 > /dev/null");
Roland McGrath 11487c5
system("cp -al $kernver linux-$patchindex");
Roland McGrath 11487c5
Roland McGrath 11487c5
# phase 2: read the spec from stdin and store all patches
Roland McGrath 11487c5
print "Reading specfile..\n";
Roland McGrath 11487c5
Roland McGrath 11487c5
while (<>) {
Roland McGrath 11487c5
	my $line = $_;
Roland McGrath 11487c5
	if ($line =~ /^Patch([0-9]+)\: ([a-zA-Z0-9\-\_\.\+]+\.patch)/) {
Roland McGrath 11487c5
		$patchlist[$1] = $2;
Roland McGrath 11487c5
	} else {
Roland McGrath 11487c5
		if ($line =~ /^Patch([0-9]+)\: ([a-zA-Z0-9\-\_\.]+\.bz2)/) {
Roland McGrath 11487c5
			$patchlist[$1] = $2;
Roland McGrath 11487c5
		}
Roland McGrath 11487c5
	}
Roland McGrath 11487c5
Roland McGrath 11487c5
	if ($line =~ /^%patch([0-9]+) -p1/) {
Roland McGrath 11487c5
		# copy the tree, apply the patch, diff and remove the old tree
Roland McGrath 11487c5
		my $oldindex = $patchindex;
Roland McGrath 11487c5
		$patchindex = $1;
Roland McGrath 11487c5
Roland McGrath 11487c5
		print "rediffing patch number $patchindex: $patchlist[$patchindex]\n";
Roland McGrath 11487c5
Roland McGrath 11487c5
		system("cp -al linux-$oldindex linux-$patchindex");
Roland McGrath 11487c5
		chdir("linux-$patchindex");
Roland McGrath 11487c5
		if ($patchlist[$patchindex] =~ /bz2/) {
Roland McGrath 11487c5
			system("bzcat $origdir/$patchlist[$patchindex] | patch -p1 &>/dev/null");
Roland McGrath 11487c5
		} else {
Roland McGrath 11487c5
			system("cat $origdir/$patchlist[$patchindex] | patch -p1 &>/dev/null");
Roland McGrath 11487c5
		}
Roland McGrath 11487c5
		chdir("$workdir");
Roland McGrath 11487c5
		system("rm -f `find -name \"*orig\"`");
Roland McGrath 11487c5
		if ($patchlist[$patchindex] =~ /bz2/) {
Roland McGrath 11487c5
		} else {
Roland McGrath 11487c5
			system("diff -urNp --exclude-from=/home/davej/.exclude linux-$oldindex linux-$patchindex | sed '$datestrip' > $patchlist[$patchindex]");
Roland McGrath 11487c5
		}
Roland McGrath 11487c5
		system("rm -rf linux-$oldindex");
Roland McGrath 11487c5
	}
Roland McGrath 11487c5
};
Roland McGrath 11487c5
Roland McGrath 11487c5
1;