summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2006-01-22 04:10:04 +0000
committerAndreas Gruenbacher <agruen@suse.de>2006-01-22 04:10:04 +0000
commitd208809b7d42c769fc966bac8afc4d7e84189488 (patch)
treec14af5195fb8d801f471ece549cc66fd943d05e5
parent76ecf965e4f0cefe633c788040862d65e7e1267d (diff)
downloadquilt-d208809b7d42c769fc966bac8afc4d7e84189488.tar.gz
- push command: when a patch doesn't apply, check if it reverse
applies, and inform the user.
-rw-r--r--quilt.changes6
-rw-r--r--quilt/push.in40
-rw-r--r--quilt/scripts/patchfns.in2
-rw-r--r--test/applied.test40
4 files changed, 81 insertions, 7 deletions
diff --git a/quilt.changes b/quilt.changes
index 352d5aa..a6ab855 100644
--- a/quilt.changes
+++ b/quilt.changes
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Sun Jan 22 05:08:12 CET 2006 - agruen@suse.de
+
+- push command: when a patch doesn't apply, check if it reverse
+ applies, and inform the user.
+
+-------------------------------------------------------------------
Sun Jan 22 03:30:09 CET 2006 - agruen@suse.de
- When inserting new diffstat, put a "---" line above it.
diff --git a/quilt/push.in b/quilt/push.in
index c50529c..89afc28 100644
--- a/quilt/push.in
+++ b/quilt/push.in
@@ -72,6 +72,8 @@ colorize()
awk '
{ if (/FAILED|hunks? ignored|can'\''t find file|file .* already exists/)
print "'$color_patch_fail'" $0 "'$color_clear'"
+ else if (/is already applied$/)
+ print "'$color_patch_applied'" $0 "'$color_clear'"
else if (/^Hunk/) {
sub(/^Hunk .* with fuzz [0-9]*/,
"'$color_patch_fuzz'&'$color_clear'")
@@ -86,6 +88,24 @@ colorize()
fi
}
+push_patch_args()
+{
+ local patch=$1
+
+ if [ -z "$opt_reverse" ]
+ then
+ patch_args "$patch"
+ else
+ set -- $(patch_args "$patch")
+ if [ "${*/-R}" != "$*" ]
+ then
+ echo "${*/-R}"
+ else
+ echo "$*" -R
+ fi
+ fi
+}
+
apply_patch()
{
local patch=$1 patch_file=$2
@@ -96,19 +116,19 @@ apply_patch()
if [ "${patch_file:(-3)}" = ".gz" ]
then
gzip -cd $patch_file \
- | patch $QUILT_PATCH_OPTS $(patch_args $patch) \
+ | patch $QUILT_PATCH_OPTS $(push_patch_args $patch) \
--backup --prefix="$QUILT_PC/$patch/" \
$no_reject_files \
-E $silent $force_apply 2>&1
elif [ "${patch_file:(-4)}" = ".bz2" ]
then
bzip2 -cd $patch_file \
- | patch $QUILT_PATCH_OPTS $(patch_args $patch) \
+ | patch $QUILT_PATCH_OPTS $(push_patch_args $patch) \
--backup --prefix="$QUILT_PC/$patch/" \
$no_reject_files \
-E $silent $force_apply 2>&1
else
- patch $QUILT_PATCH_OPTS $(patch_args $patch) \
+ patch $QUILT_PATCH_OPTS $(push_patch_args $patch) \
--backup --prefix="$QUILT_PC/$patch/" \
$no_reject_files \
-E $silent $force_apply -i $patch_file 2>&1
@@ -164,7 +184,7 @@ add_patch()
fi
apply_patch $patch "$patch_file"
- status=${PIPESTATUS[0]}
+ status=$?
trap "" SIGINT
[ -n "$tmp" ] && rm -f $tmp
@@ -199,8 +219,16 @@ add_patch()
fi
else
rollback_patch $patch
- printf $"Patch %s does not apply (enforce with -f)\n" \
- "$(print_patch $patch)"
+ opt_reverse=1
+ if apply_patch $patch "$patch_file" > /dev/null 2> /dev/null
+ then
+ rollback_patch $patch
+ printf $"Patch %s is already applied\n" \
+ "$(print_patch "$patch")"
+ else
+ printf $"Patch %s does not apply (enforce with -f)\n" \
+ "$(print_patch $patch)"
+ fi
status=1
fi
trap - SIGINT
diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in
index e518721..9edd81d 100644
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -844,7 +844,7 @@ print_patch() {
setup_colors()
{
- local C=diff_hdr=32:diff_add=36:diff_mod=35:diff_rem=35:diff_hunk=33:diff_ctx=35:diff_cctx=33:patch_offs=33:patch_fuzz=35:patch_fail=31:clear=00
+ local C=diff_hdr=32:diff_add=36:diff_mod=35:diff_rem=35:diff_hunk=33:diff_ctx=35:diff_cctx=33:patch_offs=33:patch_fuzz=35:patch_fail=31:patch_applied=32:clear=00
[ -n "$QUILT_COLORS" ] && C="$C:$QUILT_COLORS"
C=${C//=/=\'$'\e'[}
diff --git a/test/applied.test b/test/applied.test
new file mode 100644
index 0000000..b83bc83
--- /dev/null
+++ b/test/applied.test
@@ -0,0 +1,40 @@
+ $ rm -rf d
+ $ mkdir -p d/patches
+ $ cd d
+
+ $ echo a > a
+ $ echo b > b
+ $ diff -u a b > patches/patch
+ $ echo patch -p0 > patches/series
+ $ rm b
+ $ quilt push -q
+ > Applying patch patches/patch
+ > Now at patch patches/patch
+
+ $ quilt pop -q
+ > Removing patch patches/patch
+ > No patches applied
+
+ $ patch -s -p0 < patches/patch
+ $ quilt push -q
+ > Applying patch patches/patch
+ > 1 out of 1 hunk FAILED
+ > Patch patches/patch is already applied
+
+ $ echo patch -p0 -R > patches/series
+ $ quilt push -q
+ > Applying patch patches/patch
+ > Now at patch patches/patch
+
+ $ quilt pop -q
+ > Removing patch patches/patch
+ > No patches applied
+
+ $ patch -s -p0 -R < patches/patch
+ $ quilt push -q
+ > Applying patch patches/patch
+ > 1 out of 1 hunk FAILED
+ > Patch patches/patch is already applied
+
+ $ cd ..
+ $ rm -rf d