git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] xdiff: -W: relax end-of-file function detection

From
René Scharfe <l.s.r@web.de>
Date
Jan 13, 2017, 17:49 UTC
Message-ID
<23ca90e5-90a4-a03f-e51e-c82ebc75c16f@web.de>
In-Reply-To
<1484324112-17773-1-git-send-email-vegard.nossum@oracle.com>
Am 13.01.2017 um 17:15 schrieb Vegard Nossum:
Show 6 quoted lines
> When adding a new function to the end of a file, it's enough to know
> that 1) the addition is at the end of the file; and 2) there is a
> function _somewhere_ in there.
>
> If we had simply been changing the end of an existing function, then we
> would also be deleting something from the old version.
That makes sense, thanks.
Show 8 quoted lines
> This fixes the case where we add e.g.
>
> 	// Begin of dummy
> 	static int dummy(void)
> 	{
> 	}
>
> to the end of the file.

Without this patch the unchanged function before the added lines is shown in its entirety as (uncalled for) context.

Show 24 quoted lines
>
> Cc: René Scharfe <l.s.r@web.de>
> Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
> ---
>  xdiff/xemit.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/xdiff/xemit.c b/xdiff/xemit.c
> index 7389ce4..8c88dbd 100644
> --- a/xdiff/xemit.c
> +++ b/xdiff/xemit.c
> @@ -183,16 +183,14 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
>
>  				/*
>  				 * We don't need additional context if
> -				 * a whole function was added, possibly
> -				 * starting with empty lines.
> +				 * a whole function was added.
>  				 */
> -				while (i2 < xe->xdf2.nrec &&
> -				       is_empty_rec(&xe->xdf2, i2))
> +				while (i2 < xe->xdf2.nrec) {
> +					if (match_func_rec(&xe->xdf2, xecfg, i2,
> +						dummy, sizeof(dummy)) >= 0)
Nit: I don't like the indentation here.  Giving "dummy" its own line is 
also not exactly pretty, but at least would allow the parameters to be 
aligned on the opening parenthesis.
Show 11 quoted lines
> +						goto post_context_calculation;
>  					i2++;
> -				if (i2 < xe->xdf2.nrec &&
> -				    match_func_rec(&xe->xdf2, xecfg, i2,
> -						   dummy, sizeof(dummy)) >= 0)
> -					goto post_context_calculation;
> +				}
>
>  				/*
>  				 * Otherwise get more context from the
>
Previous: Vegard Nossum
Message 15 of 15 in “xdiff: -W: relax end-of-file function detection”
  1. 1/3 xdiff: -W: relax end-of-file function detectionVegard Nossum, Jan 13, 2017
  2. 2/3 xdiff: -W: include immediately preceding non-empty lines in contextVegard Nossum, Jan 13, 2017
  3. René ScharfeJan 13, 2017
  4. Stefan BellerJan 13, 2017
  5. Junio C HamanoJan 13, 2017
  6. Vegard NossumJan 13, 2017
  7. Junio C HamanoJan 13, 2017
  8. René ScharfeJan 14, 2017
  9. Junio C HamanoJan 15, 2017
  10. Vegard NossumJan 15, 2017
  11. René ScharfeJan 15, 2017
  12. Junio C HamanoJan 15, 2017
  13. René ScharfeJan 15, 2017
  14. 3/3 t/t4051-diff-function-context: improve tests for new diff -W behaviourVegard Nossum, Jan 13, 2017
  15. René ScharfeJan 13, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.