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

Re: [PATCH 2/3] xdiff: -W: include immediately preceding non-empty lines in context

From
René Scharfe <l.s.r@web.de>
Date
Jan 13, 2017, 18:19 UTC
Message-ID
<e55dc4dd-768b-8c9b-e3b2-e850d5d521f5@web.de>
In-Reply-To
<1484324112-17773-2-git-send-email-vegard.nossum@oracle.com>
Am 13.01.2017 um 17:15 schrieb Vegard Nossum:
Show 15 quoted lines
> When using -W to include the whole function in the diff context, you
> are typically doing this to be able to review the change in its entirety
> within the context of the function. It is therefore almost always
> desirable to include any comments that immediately precede the function.
>
> This also the fixes the case for C where the declaration is split across
> multiple lines (where the first line of the declaration would not be
> included in the output), e.g.:
>
> 	void
> 	dummy(void)
> 	{
> 		...
> 	}
>

That's true, but I'm not sure "non-empty line before function line" is good enough a definition for desirable lines. It wouldn't work for people who don't believe in empty lines. Or for those that put a blank line between comment and function. (I have an opinion on such habits, but git diff should probably stay neutral.) And that's just for C code; I have no idea how this heuristic would hold up for other file types like HTML.

We can identify function lines with arbitrary precision (with a xfuncname regex, if needed), but there is no accurate way to classify lines as comments, or as the end of functions. Adding optional regexes for single- and multi-line comments would help, at least for C.

René
Previous: Vegard NossumNext: Stefan Beller
Message 3 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.