summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2009-12-23 00:15:30 +0100
committerAndreas Gruenbacher <agruen@suse.de>2009-12-23 00:15:30 +0100
commite2218ace733e2a1ddc8a41dc62dce96cce956a8c (patch)
treeb8096569d8bdab9546064a7af5f64547e25de2ca
parent84f303c1ef88b863262262b1e3378cfd6a8a9864 (diff)
downloadpatch-e2218ace733e2a1ddc8a41dc62dce96cce956a8c.tar.gz
* src/pch.c (intuit_diff_type): Fix regression introduced after patch
2.5.9: when none of the filenames in the old, new, and index headers exists, patch chose the wrong filename (bug 28367). (maybe_reverse): Return if the patch looks reversed, not if this function toggled the reverse flag. * tests/filename-choice: New test case. * Makefile.in (TESTS): Add test case.
-rw-r--r--ChangeLog8
-rw-r--r--Makefile.in1
-rw-r--r--src/pch.c39
-rw-r--r--tests/filename-choice32
4 files changed, 59 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index fd22f6b..724053a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,14 @@
* src/pch.c (intuit_diff_type): Add some clarifying comments.
+ * src/pch.c (intuit_diff_type): Fix regression introduced after patch
+ 2.5.9: when none of the filenames in the old, new, and index headers
+ exists, patch chose the wrong filename (bug 28367).
+ (maybe_reverse): Return if the patch looks reversed, not if this
+ function toggled the reverse flag.
+ * tests/filename-choice: New test case.
+ * Makefile.in (TESTS): Add test case.
+
2009-11-14 Andreas Gruenbacher <agruen@suse.de>
* update-version.sh: Platform compatibility fixes.
diff --git a/Makefile.in b/Makefile.in
index 2c5fb95..04a72ce 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -197,6 +197,7 @@ TESTS = \
tests/corrupt-reject-files \
tests/create-delete \
tests/crlf-handling \
+ tests/filename-choice \
tests/global-reject-files \
tests/inname \
tests/line-numbers \
diff --git a/src/pch.c b/src/pch.c
index a641e12..6982ca3 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -195,23 +195,22 @@ grow_hunkmax (void)
}
static bool
-maybe_reverse (char const *name, bool nonexistent, bool empty)
+maybe_reverse (char const *name, bool nonexistent, bool is_empty)
{
- bool is_empty = nonexistent || empty;
- bool r;
-
- r = (! is_empty) < p_says_nonexistent[reverse ^ is_empty]
- && ok_to_reverse ("The next patch%s would %s the file %s,\nwhich %s!",
- reverse ? ", when reversed," : "",
- (nonexistent ? "delete"
- : empty ? "empty out"
- : "create"),
- quotearg (name),
- (nonexistent ? "does not exist"
- : empty ? "is already empty"
- : "already exists"));
- reverse ^= r;
- return r;
+ bool looks_reversed = (! is_empty) < p_says_nonexistent[reverse ^ is_empty];
+
+ if (looks_reversed)
+ reverse ^=
+ ok_to_reverse ("The next patch%s would %s the file %s,\nwhich %s!",
+ reverse ? ", when reversed," : "",
+ (nonexistent ? "delete"
+ : is_empty ? "empty out"
+ : "create"),
+ quotearg (name),
+ (nonexistent ? "does not exist"
+ : is_empty ? "is already empty"
+ : "already exists"));
+ return looks_reversed;
}
/* True if the remainder of the patch file contains a diff of some sort. */
@@ -681,12 +680,10 @@ intuit_diff_type (bool need_header)
}
}
- if (i != NONE && st[i].st_size > 0)
- i0 = i;
if (i0 != NONE
- && ! maybe_reverse (p_name[i0], i == NONE,
- i == NONE || st[i].st_size == 0))
- i = i0;
+ && maybe_reverse (p_name[i0], i == NONE,
+ i == NONE || st[i].st_size == 0))
+ i = i0;
if (i == NONE && p_says_nonexistent[reverse])
{
diff --git a/tests/filename-choice b/tests/filename-choice
new file mode 100644
index 0000000..f665afb
--- /dev/null
+++ b/tests/filename-choice
@@ -0,0 +1,32 @@
+# Copyright (C) 2009 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# in any medium, are permitted without royalty provided the copyright
+# notice and this notice are preserved.
+
+# Don't recognize hunks before a filename has been specified/seen
+
+. $srcdir/test-lib.sh
+
+require_cat
+use_local_patch
+use_tmpdir
+
+# ==============================================================
+
+#export GDB=1
+
+cat > f.diff <<EOF
+--- f
++++ f.new
+@@ -0,0 +1 @@
++content
+EOF
+
+check 'patch -p0 < f.diff' <<EOF
+patching file f
+EOF
+
+check 'cat f' <<EOF
+content
+EOF