Check all '^Patch\d+' lines and '^%patch' lines are matching.
authorlace <>
Thu, 9 Nov 2006 08:21:38 +0000 (08:21 +0000)
committerlace <>
Thu, 9 Nov 2006 08:21:38 +0000 (08:21 +0000)
bin/checkspecpatch [new file with mode: 0755]

diff --git a/bin/checkspecpatch b/bin/checkspecpatch
new file mode 100755 (executable)
index 0000000..7f89ae9
--- /dev/null
@@ -0,0 +1,41 @@
+#! /usr/bin/perl
+# $Id$
+# Check all '^Patch\d+' lines and '^%patch' lines are matching.
+
+use strict;
+use warnings;
+
+@ARGV=<*.spec> if !@ARGV;
+
+my $rc=0;
+for $ARGV (@ARGV) {
+       local *FILE;
+       open FILE,$ARGV or die "open $ARGV: $!";
+       my $file=do { undef $/; <FILE>; } or die "read $ARGV: $!";
+       close FILE or die "close $ARGV: $!";
+
+       my @source =sort { $a<=>$b; } ($file=~/^\s*patch(\d+)\s*:/mig);
+       my @apply  =sort { $a<=>$b; } ($file=~/^\s*%patch(\d+)\b/mig);
+       my @applyno=sort { $a<=>$b; } ($file=~/^#+\s*%patch(\d+)\b/mig);
+       my %applyno=map(($_=>1),@applyno);
+       while (@source || @apply) {
+               my $source=(shift @source)||"";
+               my $apply =(shift @apply)||"";
+               next if $source eq $apply;
+               if ($source ne "" && $apply  < $source) {
+                       unshift @source,$source;
+                       warn "$ARGV: excessive: ".'%'."patch$apply\n";
+                       $rc=1;
+               }       
+               if ($apply  ne "" && $source < $apply) {
+                       unshift @apply,$apply;
+                       if (!$applyno{$source}) {
+                               warn "$ARGV: excessive: Patch$source\n";
+                               $rc=1;
+                       } else {
+                               warn "$ARGV: (commented ".'%'."patch$source: Patch$source)\n";
+                       }
+               }
+       }
+}
+exit $rc;