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

Re: [PATCH] v5 #3460

From: Stefan Sperling <stsp_at_elego.de>
Date: Thu, 28 Jan 2010 16:34:08 +0100

On Thu, Jan 28, 2010 at 04:03:01PM +0100, Daniel Näslund wrote:
> @@ -588,18 +592,19 @@
> return SVN_NO_ERROR;
> }
>
> -/* Indicate in *MATCHED whether the original text of HUNK
> - * matches the patch TARGET at its current line.
> - * When this function returns, neither TARGET->CURRENT_LINE nor the
> - * file offset in the target file will have changed.
> - * HUNK->ORIGINAL_TEXT will be reset.
> - * Do temporary allocations in POOL. */
> +/* 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/

> + * TARGET->CURRENT_LINE nor the file offset in the target file will have
> + * changed. HUNK->ORIGINAL_TEXT will be reset. Do temporary allocations in
> + * POOL. */
> static svn_error_t *
> match_hunk(svn_boolean_t *matched, patch_target_t *target,
> - const svn_hunk_t *hunk, apr_pool_t *pool)
> + const svn_hunk_t *hunk, int fuzz, apr_pool_t *pool)
> {
> svn_stringbuf_t *hunk_line;
> const char *target_line;
> + svn_linenum_t lines_read = 0;
> svn_linenum_t saved_line;
> svn_boolean_t hunk_eof;
> svn_boolean_t lines_matched;
> @@ -630,9 +635,20 @@
> eol_str, FALSE,
> target->keywords, FALSE,
> iterpool));
> + lines_read++;
> +
> SVN_ERR(read_line(target, &target_line, iterpool, iterpool));
> +

Another extra line here. Do we really need to add it?

> if (! hunk_eof)
> - lines_matched = ! strcmp(hunk_line_translated, target_line);
> + {
> + if (lines_read <= fuzz && hunk->leading_context > fuzz)
> + lines_matched = TRUE;
> + else if (lines_read > hunk->original_length - fuzz &&
> + hunk->trailing_context > fuzz)
> + lines_matched = TRUE;
> + else
> + lines_matched = ! strcmp(hunk_line_translated, target_line);
> + }
> }
> while (lines_matched && ! (hunk_eof || target->eof));
>
> @@ -720,14 +736,15 @@
>
> /* Determine the line at which a HUNK applies to the TARGET file,
> * and return an appropriate hunk_info object in *HI, allocated from
> - * RESULT_POOL. If no correct line can be determined,
> - * set HI->MATCHED_LINE to zero.
> + * 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./

> + * be determined, set HI->MATCHED_LINE to zero.
> * When this function returns, neither TARGET->CURRENT_LINE nor the
> * file offset in the target file will have changed.
> * Do temporary allocations in POOL. */
> static svn_error_t *
> get_hunk_info(hunk_info_t **hi, patch_target_t *target,
> - const svn_hunk_t *hunk, apr_pool_t *result_pool,
> + const svn_hunk_t *hunk, int fuzz, apr_pool_t *result_pool,
> apr_pool_t *scratch_pool)
> {
> svn_linenum_t matched_line;
> @@ -778,6 +795,7 @@
> (*hi)->hunk = hunk;
> (*hi)->matched_line = matched_line;
> (*hi)->rejected = FALSE;
> + (*hi)->fuzz = fuzz;
>
> return SVN_NO_ERROR;
> }
> @@ -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 offset
> + * from the beginning or end of hunk. N represents the number of lines in
> + * HUNK_TEXT. It is ignored if FUZZ is zero. */
> static svn_error_t *
> -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.

Stefan
Received on 2010-01-28 16:34:46 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.