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

[PATCH] v3 #3460

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

On Wed, Jan 27, 2010 at 11:52:33PM +0000, Julian Foad wrote:
> Daniel Näslund wrote:
> > Removed some debug statements.
> >
> > On Wed, Jan 27, 2010 at 08:59:02PM +0100, Daniel Näslund wrote:
> > [[[
> > Fix #3460 - svn patch is not fuzzy when applying unidiffs.
> >
> [...]
>
> Hi Daniel. Just one quick kind of comment from me: can you make sure all
> the functions have doc strings, at least documenting any new parameters
> that you are adding. Even when it seems "obvious".
 
Fixed!

> > @@ -833,13 +851,17 @@
> > /* Copy HUNK_TEXT into TARGET, line by line, such that the line filter
> > * and transformation callbacks set on HUNK_TEXT by the diff parsing
> > * code in libsvn_diff will trigger. ABSPATH is the absolute path to the
> > - * file underlying TARGET. */
> > + * file underlying TARGET. Do not copy the lines that is within FUZZ steps
> > + * from the beginning or end of hunk unless NR_OF_LINES is set to 0. Then we
> > + * copy each line of HUNK_TEXT. */
> > static svn_error_t *
> > copy_hunk_text(svn_stream_t *hunk_text, svn_stream_t *target,
> > - const char *abspath, apr_pool_t *scratch_pool)
> > + const char *abspath, int fuzz, int nr_of_lines,
> > + apr_pool_t *scratch_pool)
>
> Here you mention both of the new parameters but you need to document
> what NR_OF_LINES does if it is not zero.

Done!
 
>
> > @@ -895,15 +931,19 @@
> > return SVN_NO_ERROR;
> > }
> >
> > -/* Apply a hunk described by hunk info HI to a patch TARGET.
> > +/* Apply a hunk described by hunk info HI to a patch TARGET. If we have FUZZ
> > + * use the lines from the target for those lines instead of the hunk lines.
> > * Do all allocations in POOL. */
> > static svn_error_t *
> > -apply_one_hunk(patch_target_t *target, hunk_info_t *hi, apr_pool_t *pool)
> > +apply_one_hunk(patch_target_t *target, hunk_info_t *hi,
> > + apr_pool_t *pool)
>
> Here it looks like there should be a parameter called FUZZ but there
> isn't.
 
hunk_info_t contains a field called fuzz. The idea is that hunk_info_t
contains the hunk and information about the matching. It answers theese
questions: Where did it match? Was it rejected? How much fuzz was
needed to match? From the abstraction point of view it perhaps would
have been better to shield apply_one_hunk() internally from the notion
of fuzz and just use it in get_hunk_info() but then I would have needed
to make some recursive calls. This was an easier solution.

The call chain:
  apply_one_hunk()
  get_hunk_info()
  scan_for_match()
  match_hunk()

The log message:

[[[
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>
]]]

Daniel

Received on 2010-01-28 09:04:36 CET

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.