[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] v6 #3460

From: Daniel Näslund <daniel_at_longitudo.com>
Date: Thu, 28 Jan 2010 18:10:38 +0100

On Thu, Jan 28, 2010 at 04:34:08PM +0100, Stefan Sperling wrote:
> On Thu, Jan 28, 2010 at 04:03:01PM +0100, Daniel Näslund wrote:
> > @@ -588,18 +592,19 @@
> > +/* Indicate in *MATCHED whether the original text of HUNK matches the patch
> > + * TARGET at its current line. Lines within FUZZ lines of the start or end
> > + * of hunk will always match. When this function returns, neither
> s/of hunk will/of HUNK will/

> > @@ -630,9 +635,20 @@
> > + lines_read++;
> > +
> > SVN_ERR(read_line(target, &target_line, iterpool, iterpool));
> > +
> Another extra line here. Do we really need to add it?


> > @@ -720,14 +736,15 @@
> > + * RESULT_POOL. Always set lines at start and end of HUNK text that is within
> > + * FUZZ offset to be matching. Set HI->FUZZ to FUZZ. If no correct line can
> s/Always set [blah blah] to be matching./Use fuzz factor FUZZ./

> > @@ -833,13 +851,17 @@
> > -copy_hunk_text(svn_stream_t *hunk_text, svn_stream_t *target,
> > - const char *abspath, apr_pool_t *scratch_pool)
> > +copy_hunk_lines(svn_stream_t *hunk_text, svn_stream_t *target,
> > + const char *abspath, int fuzz, int n,
> > + apr_pool_t *scratch_pool)
> Looking at the places where copy_hunk_lines() is called, it seems
> we can simplify the parameter list of this function a lot by passing
> a hunk_info_t *hi into copy_hunk_lines(). Then we won't need the n
> and fuzz parameters, and special cases around n and fuzz can be
> handled within the function.
> And we could rename the function to copy_hunk() which is even shorter.

To copy a hunk is ambigous. When the hunk is rejected we want to copy
the diff_text, when it is accepted we want the modified_text. I'd say,
leave as is.

Same log msg as v5

Fix #3460 - svn patch is not fuzzy when applying unidiffs. Refactor some
parts of the hunk parsing while at it.

* subversion/include/private/svn_diff_private.h
  (svn_hunk_t): Add fields leading_context and trailing_context. 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. Refactored some if
    statements for increased readability.

* 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 leading_context and trailing_context 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): Rename this to ..
  (copy_hunk_lines): .. And add n 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 fuzz is zero
    we ignore n and copy all lines.
  (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>
Review by: julianfoad

Received on 2010-01-28 18:11:20 CET

This is an archived mail posted to the Subversion Dev mailing list.