summaryrefslogtreecommitdiffstats
path: root/lib/apatch.in
diff options
context:
space:
mode:
authorMartin Quinson <mquinson@debian.org>2003-01-21 09:49:29 +0000
committerMartin Quinson <mquinson@debian.org>2003-01-21 09:49:29 +0000
commit02dc4a5f8c1979e9a23f7b6851f693d29b640c4d (patch)
tree2f397f5df89f4529b89fd0e7a021238d0f290007 /lib/apatch.in
parent4d11e99bfc25e0261111d202a3a2afdf97daea5c (diff)
downloadquilt-02dc4a5f8c1979e9a23f7b6851f693d29b640c4d.tar.gz
Version 0.11, from Andreas Gruenbacher
Diffstat (limited to 'lib/apatch.in')
-rwxr-xr-xlib/apatch.in135
1 files changed, 135 insertions, 0 deletions
diff --git a/lib/apatch.in b/lib/apatch.in
new file mode 100755
index 0000000..a14d219
--- /dev/null
+++ b/lib/apatch.in
@@ -0,0 +1,135 @@
+#!/bin/sh
+
+if ! [ -r @LIB@/patchfns ]
+then
+ echo "Cannot read library @LIB@/patchfns" >&2
+ exit 1
+fi
+. @LIB@/patchfns
+
+usage()
+{
+ echo "Usage: apatch [-fq] patchname"
+ exit 1
+}
+
+interrupt()
+{
+ local pc_file=$(pc_file_name $1)
+ @LIB@/backup-files -s -f $pc_file -B .pc/$patch/ -r
+ echo "apatch interrupted by user"
+ exit 1
+}
+
+apply_patch()
+{
+ local patch=$(stripit $1)
+ local pc_file=$(pc_file_name $patch)
+ local patch_file=$(patch_file_name $patch)
+ local file status
+
+ if ! [ -e "$patch_file" ]
+ then
+ echo "No patch named $patch found."
+ return 1
+ fi
+
+ #if is_applied "$patch"
+ #then
+ # echo "$patch" is already applied
+ # return 1
+ #fi
+
+ trap "" SIGINT
+ refresh_file_list $patch
+ status=$?
+ if [ $status -eq 2 ]
+ then
+ [ -z "$opt_quiet" ] && echo "Recreated file list for $patch"
+ elif [ $status -ne 0 ]
+ then
+ return 1
+ fi
+
+ if ! @LIB@/backup-files -s -f $pc_file -B .pc/$patch/
+ then
+ exit 1
+ fi
+
+ trap "interrupt $patch" SIGINT
+ # (patch -b fails if a file appears more than once in a patch!)
+ #patch $(patch_args $patch) --no-backup-if-mismatch \
+ # -E $silent -i $patch_file
+ patch $(patch_args $patch) --no-backup-if-mismatch \
+ -E $silent -i $patch_file
+ status=$?
+ trap "" SIGINT
+
+ # Remember date/time of applying so that poppatch can
+ # avoid reverse applying the patch in the usual cases.
+ touch $pc_file
+
+ if [ $status -eq 0 -o -n "$opt_force" ]
+ then
+ add_to_db $patch
+ if [ $status -eq 0 ]
+ then
+ echo "Applied $patch"
+ rm -f $(pc_file_name $patch)~forced
+ else
+ touch $(pc_file_name $patch)~forced
+ echo "Applied $patch (forced; needs refpatch)"
+ fi
+ else
+ @LIB@/backup-files -s -f $pc_file -B .pc/$patch/ -r
+ echo "Patch $patch does not apply"
+ fi
+ trap - SIGINT
+ return $status
+}
+
+options=`getopt -o fqh -- "$@"`
+
+if [ $? -ne 0 ]
+then
+ usage
+fi
+
+eval set -- "$options"
+
+while true
+do
+ case "$1" in
+ -f)
+ opt_force=1
+ shift ;;
+ -q)
+ opt_quiet=1
+ shift ;;
+ -h)
+ usage -h ;;
+ --)
+ shift
+ break ;;
+ esac
+done
+
+if [ $# -ne 1 ]
+then
+ usage
+fi
+
+[ -n "$opt_quiet" ] && silent=-s
+
+patch=$(stripit $1)
+
+top=$(top_patch)
+if [ -n "$top" -a -e $(pc_file_name $top)~forced ]
+then
+ echo "The topmost patch $top was force applied. Please run" \
+ "refpatch before applying other patches."
+ exit 1
+fi
+
+apply_patch $patch
+