Hi!
[[[
Fix #3460 - svn patch is not fuzzy when applying unidiffs.
* subversion/include/private/svn_diff_private.h
(svn_hunk_t): Add fields context_before and context_before. They are
used for determining if there is enough context to apply a patch
with fuzz.
* subversion/libsvn_diff/parse-diff.c
(parse_next_hunk): Count number of lines of context at start and end
of hunk and save the information in hunk.
* subversion/tests/cmdline/patch_tests.py
(patch_with_fuzz): New.
(test_list): Add new test.
* subversion/libsvn_client/patch.c
(hunk_info_t): Add field fuzz.
(match_hunk): Add new parameter fuzz. Record nr of lines read and
ignore the ones at the beginning and end of the hunk that is fuzzy.
Use context_before and context_after to ignore the cases when there
isn't enough context to do fuzzy patching.
(scan_for_match): Add new parameter fuzz. Call match_hunk() with fuzz.
(get_hunk_info): Add new parameter fuzz. Call scan_for_match() with
fuzz. Save the used fuzz in hi to be used when the hunk should be
copied to the target.
(copy_hunk_text): Add nr_of_lines and fuzz parameter. Record read_lines
and only copy those who are not within the fuzz limit. They have
already been or will be copied from the target. If nr_of_lines is 0
we assume that we should copy all lines and ignore fuzz.
(apply_one_hunk): Adjust lines copied to the target to include the
context lines at the beginning of the hunk who are fuzzy. Adjust the
current_line of the target to point to the last line of the hunk
minus fuzz.
(apply_one_patch): Try to call get_hunk_info() with no fuzz. If we get
no matching line try with fuzz 1 and if that fails try with fuzz 2.
Patch by: Daniel Näslund <daniel{_AT_}longitudo.com>
]]]
copy_hunk_text() is called from two places. It can either be a
modified_text or diff_text. Diff_text contains the whole hunk and is
copied if we have a rejected hunk. There is no recording of the number
of lines. So I said that if nr_of_lines is zero then we just copy all
lines. A bit of a quick hack. I think we can do it since it's just a
local helper but someone else might object.
It's easy to make off-by-one errors. I probably should extend the test
case further. But this one at least covers:
* Fuzz at beginning of file
* Fuzz at end of file
* Fuzz with value 1
* Fuzz with value 2
* Fuzz 2 with only the second context line changed
The patch test only adds new lines. There is no removal or delete.
Daniel
Received on 2010-01-27 19:59:49 CET