Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

spec_add_patch: handle multiple patches at once

  • Loading branch information...
commit 93bd7da579128b3ab127b7927986f28510895fe9 1 parent 713266b
Ludwig Nussel lnussel authored
Showing with 35 additions and 25 deletions.
  1. +35 −25 spec_add_patch
60 spec_add_patch
View
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.