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

Re: [PATCH] v7 #3460

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

On Thu, Jan 28, 2010 at 06:29:41PM +0100, Stefan Sperling wrote:
> On Thu, Jan 28, 2010 at 06:10:38PM +0100, Daniel Näslund wrote:
> > > 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.
>
> But HI->rejected will tell you if the hunk was rejected! :)

Gah, I forgot about the rejected field.
 
> And you can pass the entire patch_target_t to give copy_hunk_lines()
> access to both the patched and rejected streams.
>
> We could rename it to emit_hunk(), flush_hunk(), hunk_done(), or something
> similar, signifying that the function is responsible for dealing with
> a hunk which has been processed.
>
> The function itself can figure out what to do with the hunk, based on
> information in the hunk_info_t, rather than having the caller figure it out.

Fixed, but with doubts. Passing only hi instead of (hi, n, fuzz) was
fine but only passing target made it harder to understand why the caller
calls copy_hunk(). But I've done it so I couldn't have been totally
against it.

A new log message.

[[[
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): .. And use just hi and target as parameters. We can
    detect what kind of hunk we're dealing with inside the function.
    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
    we're dealing with a rejected hunk we 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
           stsp
]]]

Daniel

Received on 2010-01-28 19:18:55 CET

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