summaryrefslogtreecommitdiffstats
path: root/lib/rpatch.in
diff options
context:
space:
mode:
authorMartin Quinson <mquinson@debian.org>2003-01-29 09:19:25 +0000
committerMartin Quinson <mquinson@debian.org>2003-01-29 09:19:25 +0000
commit9df01863feac767ebe01e99cfc597632416ca27a (patch)
tree27b023026b54e2db2a784ce86b7b075868eaf960 /lib/rpatch.in
parent55181ac1bcf951cc22cba26dfbca813fba2b0167 (diff)
downloadquilt-9df01863feac767ebe01e99cfc597632416ca27a.tar.gz
Version 0.21 from Andreas Gruenbacher
Diffstat (limited to 'lib/rpatch.in')
-rwxr-xr-xlib/rpatch.in148
1 files changed, 95 insertions, 53 deletions
diff --git a/lib/rpatch.in b/lib/rpatch.in
index 3c05c0a..85e8408 100755
--- a/lib/rpatch.in
+++ b/lib/rpatch.in
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/bash
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -6,16 +6,20 @@
#
# See the COPYING and AUTHORS files for more details.
-if ! [ -r @LIB@/patchfns ]
+# Read in library functions
+if [ "$(type -t patch_file_name)" != function ]
then
- echo "Cannot read library @LIB@/patchfns" >&2
- exit 1
+ if ! [ -r @LIB@/patchfns ]
+ then
+ echo "Cannot read library @LIB@/patchfns" >&2
+ exit 1
+ fi
+ . @LIB@/patchfns
fi
-. @LIB@/patchfns
usage()
{
- echo "Usage: rpatch [-fRq] patchname"
+ echo "Usage: $0 [-fRq] patchname"
exit 1
}
@@ -52,10 +56,17 @@ verify_removal()
files_may_have_changed()
{
local patch=$1 file
+ local patch_file=$(patch_file_name $patch)
local pc_file=$(pc_file_name $patch)
+
+ if ! [ -e $pc_file ]
+ then
+ return 1
+ fi
+
local apply_ts=$(date -r $pc_file '+%s') ts
- if [ $pc_file -ot $(patch_file_name $patch) ]
+ if [ -e "$patch_file" -a $pc_file -ot "$patch_file" ]
then
return 0
fi
@@ -76,25 +87,60 @@ files_may_have_changed()
return 1
}
-abort_patch()
+rollback_patch()
{
- local pc_file=$(pc_file_name $1)
- @LIB@/backup-files -s -f $pc_file -z ~rpatch -r
- exit 1
+ local patch=$1 pc_file=$(pc_file_name $patch)
+ @LIB@/backup-files $silent_unless_verbose \
+ -f $pc_file -z ~rpatch -r
+ rm -f $(files_in_patch $patch | sed -e 's/$/\.rej/')
}
interrupt()
{
local patch=$1
- abort_patch $patch
- echo "rpatch interrupted by user"
+ rollback_patch $patch
+ echo "Interrupted by user; patch $patch was not removed."
exit 1
}
-do_remove()
+reverse_patch()
+{
+ local patch=$1
+ local patch_file=$(patch_file_name $patch)
+
+ if ! [ -s $patch_file ]
+ then
+ echo "Patch file $patch_file appears to be empty"
+ return 0
+ fi
+
+ if [ "x${patch_file:(-3)}" = "x.gz" ]
+ then
+ gzip -cd $patch_file \
+ | patch $(patch_args $patch) --no-backup-if-mismatch \
+ -R -E $silent
+ elif [ "x${patch_file:(-4)}" = "x.bz2" ]
+ then
+ bzip2 -cd $patch_file \
+ | patch $(patch_args $patch) --no-backup-if-mismatch \
+ -R -E $silent
+ else
+ patch $(patch_args $patch) --no-backup-if-mismatch \
+ -R -E $silent -i $patch_file
+ fi
+}
+
+rpatch()
{
local patch=$1 pc_file=$(pc_file_name $patch)
+ if ! [ -e $pc_file ]
+ then
+ echo "Patch $patch appears to be empty, removed"
+ remove_from_db $patch
+ return 0
+ fi
+
trap "" SIGINT
if [ -n "$opt_force" ] || \
( [ -z "$opt_remove" ] && ! files_may_have_changed $patch )
@@ -106,44 +152,53 @@ do_remove()
@LIB@/backup-files $silent -f $pc_file -B .pc/$patch/ -r
status=$?
remove_from_db $patch
- rm -f $(pc_file_name $patch)~forced
- return $status
+ rm -f $pc_file~refresh
+ if [ $status != 0 ]
+ then
+ exit $status
+ fi
else
- local patch_file=$(patch_file_name $patch)
- if ! [ -e "$patch_file" ]
+ if ! @LIB@/backup-files $silent_unless_verbose \
+ -f $pc_file -z ~rpatch
then
- echo "No patch named $patch found."
+ echo "Failed to create temporary files" >&2
return 1
fi
trap "interrupt $patch" SIGINT
- #if [ ! -e $patch_file ] || grep -q '^%patch$' $patch_file
- #then
- # @LIB@/parse-patch -s patch $patch_file \
- # | patch $(patch_args $patch) --no-backup-if-mismatch \
- # -R -E $silent
- #else
- patch $(patch_args $patch) --no-backup-if-mismatch \
- -R -E $silent -i $patch_file
- #fi
+
+ reverse_patch $patch
status=$?
+
trap "" SIGINT
+
if [ $status -eq 0 ] && verify_removal $patch
then
- @LIB@/backup-files -s -f $pc_file -z ~rpatch -x
- @LIB@/backup-files -s -f $pc_file -B .pc/$patch/ -x
+ @LIB@/backup-files $silent_unless_verbose \
+ -f $pc_file -z ~rpatch -x
+ @LIB@/backup-files $silent_unless_verbose \
+ -f $pc_file -B .pc/$patch/ -x
remove_from_db $patch
else
- @LIB@/backup-files -s -f $pc_file -z ~rpatch -r
- echo "Patch $patch does not remove cleanly"
+ rollback_patch $patch
+ echo "Patch $patch does not remove (enforce with -f)"
return 1
fi
fi
trap - SIGINT
+
+ local top=$(top_patch) where
+ if [ -z "$top" ]
+ then
+ where="no patches applied"
+ else
+ where="now at $top"
+ fi
+ echo "Removed $patch, $where"
}
-options=`getopt -o fRqh -- "$@"`
+options=`getopt -o fRqvh -- "$@"`
if [ $? -ne 0 ]
then
@@ -165,6 +220,9 @@ do
-q)
opt_quiet=1
shift ;;
+ -v)
+ opt_verbose=1
+ shift ;;
-h)
usage -h ;;
--)
@@ -180,29 +238,13 @@ fi
patch=$(stripit $1)
[ -n "$opt_quiet" ] && silent=-s
+[ -z "$opt_verbose" ] && silent_unless_verbose=-s
top=$(top_patch)
-if [ -n "$top" -a -e $(pc_file_name $top)~forced -a -z "$opt_force" ]
+if [ -n "$top" -a -e $(pc_file_name $top)~refresh -a -z "$opt_force" ]
then
- echo "The topmost patch $top was force applied. Please run" \
- "refpatch before removing it."
+ echo "The topmost patch $top needs to be refreshed first."
exit 1
fi
-#if is_applied "$patch"
-#then
- do_remove "$patch" || exit 1
-#else
-# echo "Patch $patch is not applied"
-# exit 1
-#fi
-
-top=$(top_patch)
-if [ -z "$top" ]
-then
- where="no patches applied"
-else
- where="now at $top"
-fi
-echo "Removed $patch, $where"
-
+rpatch "$patch" || exit 1