applypatch.sh script

Kyle McMartin kyle at mcmartin.ca
Thu Jan 15 08:19:45 UTC 2009


I dislike looking at those
C=`wc -l ..`
if [ -gt ... ]

things in the spec-file...

How about something like this?

? prep2.log
Index: kernel.spec
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/kernel.spec,v
retrieving revision 1.1218
diff -u -p -r1.1218 kernel.spec
--- kernel.spec	15 Jan 2009 07:41:04 -0000	1.1218
+++ kernel.spec	15 Jan 2009 08:16:29 -0000
@@ -862,19 +862,12 @@ exit 1
 %endif
 %endif
 
-patch_command='patch -p1 -F1 -s'
 ApplyPatch()
 {
   local patch=$1
   shift
-  if [ ! -f $RPM_SOURCE_DIR/$patch ]; then
-    exit 1;
-  fi
-  case "$patch" in
-  *.bz2) bunzip2 < "$RPM_SOURCE_DIR/$patch" | $patch_command ${1+"$@"} ;;
-  *.gz) gunzip < "$RPM_SOURCE_DIR/$patch" | $patch_command ${1+"$@"} ;;
-  *) $patch_command ${1+"$@"} < "$RPM_SOURCE_DIR/$patch" ;;
-  esac
+  
+  $RPM_SOURCE_DIR/scripts/applypatch.sh "$RPM_SOURCE_DIR/$patch" ${1+"$@"}
 }
 
 # First we unpack the kernel tarball.
@@ -998,18 +991,12 @@ ApplyPatch linux-2.6-makefile-after_link
 #
 # misc small stuff to make things compile
 #
-C=$(wc -l $RPM_SOURCE_DIR/linux-2.6-compile-fixes.patch | awk '{print $1}')
-if [ "$C" -gt 10 ]; then
 ApplyPatch linux-2.6-compile-fixes.patch
-fi
 
 %if !%{nopatches}
 
 # revert patches from upstream that conflict or that we get via other means
-C=$(wc -l $RPM_SOURCE_DIR/linux-2.6-upstream-reverts.patch | awk '{print $1}')
-if [ "$C" -gt 10 ]; then
 ApplyPatch linux-2.6-upstream-reverts.patch -R
-fi
 
 #ApplyPatch git-cpufreq.patch
 
@@ -1151,10 +1138,7 @@ ApplyPatch linux-2.6-net-tulip-interrupt
 
 # linux1394 git patches
 #ApplyPatch linux-2.6-firewire-git-update.patch
-C=$(wc -l $RPM_SOURCE_DIR/linux-2.6-firewire-git-pending.patch | awk '{print $1}')
-if [ "$C" -gt 10 ]; then
 ApplyPatch linux-2.6-firewire-git-pending.patch
-fi
 
 # silence the ACPI blacklist code
 ApplyPatch linux-2.6-silence-acpi-blacklist.patch
Index: scripts/applypatch.sh
===================================================================
RCS file: scripts/applypatch.sh
diff -N scripts/applypatch.sh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ scripts/applypatch.sh	15 Jan 2009 08:16:29 -0000
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+patch=$1
+shift
+
+# echo "<< applying $patch "
+
+if [ ! -f $patch ]; then
+	echo "applypatch: $patch was missing!";
+	exit 1;
+fi
+
+# ignore empty patches, culls the ugly wc -l checks we had
+# around applypatch formerly...
+if [[ `diffstat $patch | grep " 0 files changed"` ]]; then
+	echo "applypatch: $patch is empty";
+	exit 0;
+fi
+
+patchcmd='patch -p1 -F1 -s'
+
+case "$patch" in
+	*.bz2) bunzip2 < "$patch" | $patchcmd ${1+"$@"} ;;
+	*.gz) gunzip < "$patch" | $patchcmd ${1+"$@"} ;;
+	*) $patchcmd ${1+"$@"} < "$patch" ;;
+esac
+
+# echo ">> "




More information about the kernel mailing list