#!/usr/bin/perl -w
# Generate the SUSE-prefered patch format on the modified files in workarea.
#
# Run this in the SUSE workarea where you have modified the files
# after fixing up the patch failures.
# It takes NO arguments but looks at the modified files in the workarea.
# It outputs to stdout and can be appended to the earlier patch file
# created by p_mod2suse.
#
use strict;

if (!defined($ENV{'WORKAREA'})) {
	print STDERR "Error: WORKAREA must be set to SUSE workarea with changes\n";
	exit 1;
}

# p_rdiff in workarea gives:
#
# ===========================================================================
# Index: linux/fs/xfs/quota/xfs_dquot.c
# ===========================================================================
#
# --- a/linux/fs/xfs/quota/xfs_dquot.c	2005-08-29 17:43:50.000000000 +1000
# +++ b/linux/fs/xfs/quota/xfs_dquot.c	2005-08-29 16:30:53.341233695 +1000
#
# But we want of form:
#
# ===========================================================================
# Index: quota/xfs_dquot.c
# ===========================================================================
#
# --- a/fs/xfs/quota/xfs_dquot.c  2005-08-29 17:18:33.000000000 +1000
# +++ b/fs/xfs/quota/xfs_dquot.c  2005-08-29 17:18:33.000000000 +1000
#

# Patch body
open PRDIFF, "p_rdiff -umpP |" or die "rdiff";
$/ = "\n===========================================================================\n";
while (<PRDIFF>) {
	s,^\-\-\- a/linux,--- a,m;
	s,^\+\+\+ b/linux,+++ b,m;
	s,^Index: linux/,Index: ,m;
	print;
}
$/ = "\n";
close PRDIFF;
