diff options
author | Andreas Gruenbacher <agruen@suse.de> | 2009-04-03 21:57:46 +0200 |
---|---|---|
committer | Andreas Gruenbacher <agruen@suse.de> | 2009-04-03 22:28:38 +0200 |
commit | 1ce9b303ce75b1657798f82c171db9919cf9daf2 (patch) | |
tree | 1227d54a8dddf368859d652d79203587b7a68e50 | |
parent | c5f41b5c4c5da8925482cf00a02bf4fcde62c242 (diff) | |
download | patch-1ce9b303ce75b1657798f82c171db9919cf9daf2.tar.gz |
If an asymmmetric hunk starts at a line > 1, it is not from the start of the file
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | NEWS | 9 | ||||
-rw-r--r-- | patch.c | 9 | ||||
-rw-r--r-- | tests/asymmetric-hunks | 58 |
4 files changed, 63 insertions, 19 deletions
@@ -19,11 +19,15 @@ ed related tests if we don't have it. * tests/merge: Use sed instead of ed: sed is more readily available. + * patch.c (locate_hunk): If a hunk starts at a line > 1, it obviously + is not from the start of the file. + * tests/asymmetric-hunks: Add tests for all possible cases. + 2009-04-02 Andreas Gruenbacher <agruen@suse.de> * patch.c (locate_hunk): Revert the assymmetric hunk fix from 2009-03-29. Instead, allow such hunks to apply only when no - more context remains (and the hunk has become symmetric). + more context remains. * patch.c (main): Restructure to get rid of some code duplication. (copy_till, similar): Export these functions. @@ -44,10 +44,11 @@ * 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 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. + 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. @@ -904,10 +904,8 @@ locate_hunk (LINENUM fuzz) LINENUM pat_lines = pch_ptrn_lines(); LINENUM prefix_context = pch_prefix_context (); LINENUM suffix_context = pch_suffix_context (); - 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 prefix_fuzz = (prefix_context < fuzz ? prefix_context : fuzz); + LINENUM suffix_fuzz = (suffix_context < fuzz ? suffix_context : fuzz); 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; @@ -922,7 +920,8 @@ locate_hunk (LINENUM fuzz) if (first_guess <= max_neg_offset) max_neg_offset = first_guess - 1; - if (prefix_context < suffix_context && fuzz < suffix_context) + if (prefix_context < suffix_context && fuzz < suffix_context + && pch_first () <= 1) { /* Can only match start of file. */ diff --git a/tests/asymmetric-hunks b/tests/asymmetric-hunks index ff657c1..83fb06d 100644 --- a/tests/asymmetric-hunks +++ b/tests/asymmetric-hunks @@ -13,7 +13,35 @@ use_tmpdir # ============================================================== -# Bug #25833: Patch fails to correctly apply hunks with asymmetric context +# Starts at a line <= 1 and prefix context < suffix context: start of file +# until all context has been stripped. + +cat > a.diff <<EOF +--- a ++++ a +@@ -1,3 +1,4 @@ + 2 ++2a + 3 + 4 +EOF + +seq 1 5 > a + +check 'patch < a.diff' <<EOF +patching file a +Hunk #1 succeeded at 1 with fuzz 2. +EOF + +seq 2 5 > a + +check 'patch < a.diff' <<EOF +patching file a +EOF + +# ============================================================== + +# Starts at a line > 1: anywhere in the file cat > a.diff <<EOF --- a @@ -25,18 +53,30 @@ 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 -Hunk #1 succeeded at 2 with fuzz 2. EOF -check 'cat a' <<EOF -1 -2 -2a -3 -4 -5 +cat > a.diff <<EOF +--- a ++++ a +@@ -2,3 +2,4 @@ + 2 + 3 ++3a + 4 +EOF + +seq 1 5 > a + +check 'patch < a.diff' <<EOF +patching file a +Hunk #1 succeeded at 2 with fuzz 2. EOF |