summaryrefslogtreecommitdiff
path: root/spec_add_patch
diff options
context:
space:
mode:
authorLudwig Nussel <ludwig.nussel@suse.de>2011-01-20 11:02:42 +0100
committerLudwig Nussel <ludwig.nussel@suse.de>2011-02-03 14:28:54 +0100
commit93bd7da579128b3ab127b7927986f28510895fe9 (patch)
treeb9ee3564de760409d826d79724c0bde7596162d8 /spec_add_patch
parent713266b8e8e406135ab6f615a1d3cd6e1dfe5d25 (diff)
downloadobs-build-93bd7da579128b3ab127b7927986f28510895fe9.tar.gz
obs-build-93bd7da579128b3ab127b7927986f28510895fe9.tar.bz2
obs-build-93bd7da579128b3ab127b7927986f28510895fe9.zip
spec_add_patch: handle multiple patches at once
Diffstat (limited to 'spec_add_patch')
-rwxr-xr-xspec_add_patch60
1 files changed, 35 insertions, 25 deletions
diff --git a/spec_add_patch b/spec_add_patch
index 5f81824..fd62753 100755
--- a/spec_add_patch
+++ b/spec_add_patch
@@ -4,13 +4,21 @@
use strict;
-my $diffname = $ARGV[0];
-my $specname = $ARGV[1];
+sub helpexit {
+ print "$0: <patches...> [file.spec]\n";
+ exit 1;
+}
-if (!defined($diffname) || ! -f $diffname) {
+my $specname;
+my %diffs;
- print "$0: <diffname>\n";
- exit 1;
+for my $arg (@ARGV) {
+ if ($arg =~ /\.spec$/) {
+ helpexit() if $specname;
+ $specname = $arg;
+ next;
+ }
+ $diffs{$arg} = 1;
}
sub find_specfile()
@@ -36,7 +44,6 @@ my $in_prep = 0;
my $in_global = 1;
my $last_patch_in_prep_index = 0;
my $last_patch_in_global_index = 0;
-my $already_found_patch = 0;
my @c = ();
my $index = 0;
@@ -73,18 +80,18 @@ while(<S>)
die if (($in_prep + $in_global) > 1);
- if ($in_global && /^Patch(?:\d+)?:/) {
+ if ($in_global && /^Patch(?:\d+)?:\s+(.+)/) {
$last_patch_in_global_index = $index;
+ if ($diffs{$1}) {
+ print "$1 already in, skipped.";
+ delete $diffs{$1};
+ }
}
if ($in_global && $ifdef_level == 0 && /^Source(?:\d+)?:/) {
$last_patch_in_global_index = $index;
}
- if ($in_global && /^Patch.*?:\s+$diffname/) {
- $already_found_patch = 1;
- }
-
if ($in_prep && $ifdef_level == 0 && /^\%patch/) {
$last_patch_in_prep_index = $index;
}
@@ -93,10 +100,6 @@ while(<S>)
}
close(S);
-exit 0 if ($already_found_patch);
-
-print "Adding patch $diffname to $specname\n";
-
die if ($ifdef_level > 0);
die if ($in_global || $in_prep);
die if ($last_patch_in_prep_index == 0);
@@ -110,20 +113,27 @@ my $patchnum = 0;
$patchnum = $1+1 if ($c[$last_patch_in_global_index] =~ /Patch(\d+):/);
$patchnum = 1 if ($c[$last_patch_in_global_index] =~ /Patch:/);
-# determine strip level
-my $striplevel = "";
-open(P, '<', $diffname) or die;
-while(<P>) {
- $striplevel = " -p1" if (m/^--- a/ or m/^--- [^\/]+-\d+\./);
- last if (/^--- /);
+for my $diffname (keys %diffs) {
+ # determine strip level
+ my $striplevel = "";
+ open(P, '<', $diffname) or die "$diffname: $!\n";
+ while(<P>) {
+ $striplevel = " -p1" if (m/^--- a/ or m/^--- [^\/]+-\d+\./);
+ last if (/^--- /);
-}
-close(P);
+ }
+ close(P);
+ print "Adding patch$striplevel $diffname to $specname\n";
-splice @c, $last_patch_in_prep_index+1, 0, ("\%patch$patchnum$striplevel\n");
-splice @c, $last_patch_in_global_index+1, 0,
+
+ splice @c, $last_patch_in_prep_index+1, 0, ("\%patch$patchnum$striplevel\n");
+ splice @c, $last_patch_in_global_index+1, 0,
(sprintf "Patch%s:%s%s\n", $patchnum, ' ' x (10-length($patchnum)), $diffname);
+ ++$last_patch_in_global_index;
+ $last_patch_in_prep_index+=2; # actually line number
+ ++$patchnum;
+}
open(O, '>', "$specname.new") or die;
print O @c;