summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2009-04-05 20:23:36 +0200
committerAndreas Gruenbacher <agruen@suse.de>2009-04-05 20:24:04 +0200
commit802b26e78d0ab33440989d03d96c3be3f211c420 (patch)
treea27ae31054e5c2c6c6d9b5762cf3300c174db609
parent018b7b56c0baa515d924dbdbe8bb1a7d5a91307f (diff)
downloadpatch-802b26e78d0ab33440989d03d96c3be3f211c420.tar.gz
Revert (almost) to the original asymmetric hunk behavior and document that
-rw-r--r--ChangeLog7
-rw-r--r--NEWS9
-rw-r--r--patch.man6
-rw-r--r--src/patch.c13
-rw-r--r--tests/asymmetric-hunks18
5 files changed, 30 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 6b0a63f..6a6248a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -65,6 +65,13 @@
that keepeing them here as introduced.
* tests/backup-prefix-suffix: Add more regression tests.
+ * src/patch.c (locate_hunk): Revert to the original asymmetric hunk
+ behavior (but only anchor hunks starting at line 0 to the start of the
+ file): there is not enough reason to change the historic behavior.
+ * tests/asymmetric-hunks: Update accordingly.
+ * patch.man: Document the asymmetric hunk behavior.
+ * NEWS: Update.
+
2009-04-04 Andreas Gruenbacher <agruen@suse.de>
* pch.c (another_hunk): Add (back) the line number ranges to the
diff --git a/NEWS b/NEWS
index 8874d97..6144684 100644
--- a/NEWS
+++ b/NEWS
@@ -32,9 +32,6 @@
line endings in patches. This allows to preserve CRs even in mangled
patches, or in patches generated without the --binary option on non-POSIX
systems.
-* Hunks with a different number of lines in the prefix and suffix context
- can now apply anywhere in the file, rather than only at the beginning
- (shorter prefix context) or at the end (shorter suffix context).
* Backup files for nonexisting files are now created with default
permissions rather than with mode 0: backup files with mode 0 were
causing problems with applications which do not expect unreadable
@@ -43,12 +40,6 @@
imply the simple version control mode, and can be combined.
* Reject more malformed normal format commands and check for trailing
garbage. Recognize ed commands without addresses.
-* As seemingly originally intended, patch will assume that hunks with fewer
- lines of prefix than suffix context which start at line 1 must apply at the
- beginning of the file, while hunks with fewer lines of suffix context must
- apply at the end of the file. If a high-enough fuzz factor is allowed to
- strip off all context (which is not the default), such hunks can also apply
- within a file.
* Handle missing timestamps better.
* Various bug fixes.
diff --git a/patch.man b/patch.man
index fc95e2b..1f71a4e 100644
--- a/patch.man
+++ b/patch.man
@@ -94,6 +94,12 @@ If that fails, and the maximum fuzz factor is set to 2 or more,
the first two and last two lines of context are ignored,
and another scan is made.
(The default maximum fuzz factor is 2.)
+.PP
+Hunks with less prefix context than suffix context (after applying fuzz)
+must apply at the start of the file if their first line number is\ 1. Hunks
+with more prefix context than suffix context (after applying fuzz) must apply
+at the end of the file.
+.PP
If
.B patch
cannot find a place to install that hunk of the patch, it puts the
diff --git a/src/patch.c b/src/patch.c
index d8c7390..e197741 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -900,8 +900,10 @@ locate_hunk (LINENUM fuzz)
LINENUM pat_lines = pch_ptrn_lines();
LINENUM prefix_context = pch_prefix_context ();
LINENUM suffix_context = pch_suffix_context ();
- LINENUM prefix_fuzz = (prefix_context < fuzz ? prefix_context : fuzz);
- LINENUM suffix_fuzz = (suffix_context < fuzz ? suffix_context : fuzz);
+ LINENUM context = (prefix_context < suffix_context
+ ? suffix_context : prefix_context);
+ LINENUM prefix_fuzz = fuzz + prefix_context - context;
+ LINENUM suffix_fuzz = fuzz + suffix_context - context;
LINENUM max_where = input_lines - (pat_lines - suffix_fuzz) + 1;
LINENUM min_where = last_frozen_line + 1 - (prefix_context - prefix_fuzz);
LINENUM max_pos_offset = max_where - first_guess;
@@ -916,8 +918,7 @@ locate_hunk (LINENUM fuzz)
if (first_guess <= max_neg_offset)
max_neg_offset = first_guess - 1;
- if (prefix_context < suffix_context && fuzz < suffix_context
- && pch_first () <= 1)
+ if (prefix_fuzz < 0 && pch_first () <= 1)
{
/* Can only match start of file. */
@@ -937,8 +938,10 @@ locate_hunk (LINENUM fuzz)
else
return 0;
}
+ else if (prefix_fuzz < 0)
+ prefix_fuzz = 0;
- if (suffix_context < prefix_context && fuzz < prefix_context)
+ if (suffix_fuzz < 0)
{
/* Can only match end of file. */
offset = first_guess - (input_lines - pat_lines + 1);
diff --git a/tests/asymmetric-hunks b/tests/asymmetric-hunks
index 83fb06d..da85024 100644
--- a/tests/asymmetric-hunks
+++ b/tests/asymmetric-hunks
@@ -13,8 +13,8 @@ use_tmpdir
# ==============================================================
-# Starts at a line <= 1 and prefix context < suffix context: start of file
-# until all context has been stripped.
+# Starts at a line <= 1 and prefix context < suffix context: start of
+# file until hunk has become symmetric.
cat > a.diff <<EOF
--- a
@@ -30,7 +30,7 @@ seq 1 5 > a
check 'patch < a.diff' <<EOF
patching file a
-Hunk #1 succeeded at 1 with fuzz 2.
+Hunk #1 succeeded at 2 with fuzz 1 (offset 1 line).
EOF
seq 2 5 > a
@@ -53,17 +53,17 @@ cat > a.diff <<EOF
4
EOF
-# ==============================================================
-
-# Prefix context > suffix context: en dof file until all context has been
-# stripped.
-
seq 1 5 > a
check 'patch < a.diff' <<EOF
patching file a
EOF
+# ==============================================================
+
+# Prefix context > suffix context: end of file until hunk has
+# become symmetric.
+
cat > a.diff <<EOF
--- a
+++ a
@@ -78,5 +78,5 @@ seq 1 5 > a
check 'patch < a.diff' <<EOF
patching file a
-Hunk #1 succeeded at 2 with fuzz 2.
+Hunk #1 succeeded at 2 with fuzz 1.
EOF