r1039 - in trunk/kernel-2.4/source/kernel-source-2.4.27-2.4.27: . debian

Joshua Kwan joshk@haydn.debian.org
Thu, 12 Aug 2004 13:29:07 -0600


Author: joshk
Date: 2004-08-12 13:29:03 -0600 (Thu, 12 Aug 2004)
New Revision: 1039

Modified:
   trunk/kernel-2.4/source/kernel-source-2.4.27-2.4.27/
   trunk/kernel-2.4/source/kernel-source-2.4.27-2.4.27/debian/apply
Log:
debian/apply kicks so much ass now it hurts



Property changes on: trunk/kernel-2.4/source/kernel-source-2.4.27-2.4.27
___________________________________________________________________
Name: svn:ignore
   + kernel
crypto
include
net
scripts
README
CREDITS
init
lib
Rules.make
REPORTING-BUGS
fs
COPYING
mm
Documentation
MAINTAINERS
ipc
arch
Makefile
drivers


Modified: trunk/kernel-2.4/source/kernel-source-2.4.27-2.4.27/debian/apply
===================================================================
--- trunk/kernel-2.4/source/kernel-source-2.4.27-2.4.27/debian/apply	2004-08-12 16:35:53 UTC (rev 1038)
+++ trunk/kernel-2.4/source/kernel-source-2.4.27-2.4.27/debian/apply	2004-08-12 19:29:03 UTC (rev 1039)
@@ -13,7 +13,7 @@
 }
 
 uncompress_patch() {
-	patch=shift
+	patch=$1
 	case "$patch" in
 		*.bz2) bzcat $patch ;;
 		*.gz) zcat $patch ;;
@@ -22,27 +22,51 @@
 }
 
 apply_patch() {
-	patch=shift
-	[ -f "$patch" ] || die "$patch does not exist, but is in the series!"
-	uncompress_patch "$patch" | patch -p1 
+	patch=$1
+	[ -f "$home/$patch" ] || die "$patch does not exist, but is in the series!"
+	if uncompress_patch "$home/$patch" | patch -p1 -s -t; then
+		printf "%-32s\tOK (+)\n" "$patch"
+	else
+		printf "%-32s\tFAIL (+)\n" "$patch"
+		exit 1
+	fi
 }
 
 deapply_patch() {
-	patch=shift
-	[ -f "$patch" ] || die "$patch does not exist, but is in the series!"
-	uncompress_patch "$patch" | patch -p1 -R
+	patch=$1
+	[ -f "$home/$patch" ] || die "$patch does not exist, but is in the series!"
+	if uncompress_patch "$home/$patch" | patch -p1 -s -t -R; then
+		printf "%-32s\tOK (-)\n" "$patch"
+	else
+		printf "%-32s\tFAIL (-)\n" "$patch"
+		exit 1
+	fi
 }
 
-process_series() {
-	series=shift
+unpatch_series() {
+	series=$1
 	[ -f "$series" ] || die "I wasn't passed a series!"
 
+	tac $series | while read action patch; do
+		case "$action" in
+			+) deapply_patch $patch ;;
+			-) apply_patch $patch ;;
+		esac
+	done 
+	echo "--> $(basename $series) fully unapplied."
+}
+
+patch_series() {
+	series=$1
+	[ -f "$series" ] || die "I wasn't passed a series!"
+
 	while read action patch; do
 		case "$action" in
 			+) apply_patch $patch ;;
 			-) deapply_patch $patch ;;
 		esac
 	done < $series
+	echo "--> $(basename $series) fully applied."
 }
 
 if ! [ -d Documentation ] || ! [ -d kernel ]; then
@@ -55,46 +79,91 @@
 upstream=${version%-*}
 revision=${version#*-}
 
-home=/usr/src/kernel-patches/all/$upstream/debian
+home=${home:-/usr/src/kernel-patches/all/$upstream/debian}
 
 if [ -f version.Debian ]; then
 	current=$(cat version.Debian)
+	current_rev=${current#*-}
+	current_up=${current%-*}
+
+	if [ "$current" = "$upstream" ]; then
+		current_rev=0
+	fi
 else
 	warn "No version.Debian file, assuming pristine Linux $upstream"
 	current=$upstream
+	current_rev=0
 fi
 
 target=${1:-$version}
+
 target_rev=${target#*-}
 target_up=${target%-*}
 
-current_rev=${current#*-}
-current_up=${current%-*}
-
+# Sanity checks
 if [ "$target_up" != "$upstream" ]; then
 	die "Upstream $target_up doesn't match $upstream!"
+# We don't have that version out yet!
+elif [ ! -n "$target_rev" ] || ( [ "$target_rev" != "$target" ] && [ $target_rev -gt $revision ] ); then
+	year=$(($(date +%Y) + 1))
+	die "Can't patch to nonexistent revision $target_rev (wait until $year)"
 fi
 
 # At this point, we must handle three cases.
-# 1. $target_rev is greater than $revision. We must patch forward for this.
-# 2. $target_rev is less than $revision. We must reverse the list of series,
+# 1. $target_rev is greater than $current_rev. We must patch forward for this.
+# 2. $target_rev is less than $current_rev. We must reverse the list of series,
 #    reverse each used series (tac) and unapply applied patches and vice versa.
 # 3. $target_rev is undefined, and $target is $upstream.
 
 # Revert to upstream.
-if [ -z "$target_rev" ]; then
-fi
+if [ "$target_rev" = "$target" ]; then
+	# already reverted
+	if [ "$current" = "$target" ]; then 
+		echo "Nothing to do, exiting."
+		exit 0
+	fi
 
-for sver in $home/series/*; do
-	base=$(basename "$sver")
-	srev=${base#*-}
-	if [ -n "$srev" ]; then
-		if [ $srev -gt $revision ]; then
-			patch_series $sver
+	for sver in $(find $home/series/ -type f| sort -r); do
+		base=$(basename "$sver")
+		srev=${base#*-}
+		if [ -n "$srev" ]; then
+			if [ $srev -le $current_rev ]; then
+				unpatch_series $sver
+			fi
+		else
+			die "Series doesn't have a revision!"
 		fi
-	fi
-done
+	done
+elif [ "$current_rev" = "$upstream" ] || [ $target_rev -gt $current_rev ]; then
+	for sver in $home/series/*; do
+		base=$(basename "$sver")
+		srev=${base#*-}
+		if [ -n "$srev" ]; then
+			if [ $srev -gt $current_rev ]; then
+				patch_series $sver
+			fi
+		else
+			die "Series doesn't have a revision!"
+		fi
+	done
+elif [ $target_rev -eq $current_rev ]; then
+	echo "Nothing to do, exiting."
+	exit 0
+elif [ $target_rev -lt $current_rev ]; then
+	for sver in $(find $home/series/ -type f | sort -r); do
+		base=$(basename "$sver")
+		srev=${base#*-}
+		if [ -n "$srev" ]; then
+			# -gt because you don't want to unapply the target series
+			if [ $srev -le $current_rev ] && [ $srev -gt $target_rev ]; then
+				unpatch_series $sver
+			fi
+		else
+			die "Series doesn't have a revision!"
+		fi
+	done
+fi
 
-echo $intended > version.Debian
+echo $target > version.Debian
 
-# vim:noet:ai:ts=8
+# vim:noet:ai:ts=4