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

Re: [Bug?] log -p -W showing the whole file for a patch that adds to the end?

From
René Scharfe <l.s.r@web.de>
Date
May 21, 2016, 18:42 UTC
Message-ID
<5740AC28.6010202@web.de>
In-Reply-To
<xmqq4ma5msrd.fsf@gitster.mtv.corp.google.com>
Am 11.05.2016 um 00:51 schrieb Junio C Hamano:
Show 7 quoted lines
> The helper function get_func_line() however gets confused when a
> hunk adds a new function at the very end, and returns -1 to signal
> that it did not find a suitable "function header line", i.e. the
> beginning of previous function.  The caller then takes this signal
> and shows from the very beginning of the file.  We end up showing
> the entire file, starting from the very beginning to the end of the
> newly added lines.

In this case we need to look at the added lines in the post-image to see if the original context suffices. We currently only look at the pre-image. And if we have to extend the context simply search from the bottom of the pre-image. That's what the second patch does; the first one is just a small preparation.

The last three patches introduce special handling of empty lines. Before them the code for -W only distinguished between function lines and non-function lines. Not allowing empty lines between functions to extend the context with -W is most useful in the case of appended full functions -- otherwise we'd get the preceding function shown as well as it "belongs" to the empty line separating them.

And if we do that then it's easy and more consistent to stop showing empty lines trailing functions with -W (unless they're already included in the one requested with -u/-U, of course). Doing the same for grep then is only fair.

Considering empty lines as uninteresting collides with languages like Whitespace. I'm not sure -W was useful for it to begin with, though. Any other possible downsides?

NB: Comments are still not handled specially.  That means they are
considered to be part of the preceding function.  Fixing that is not in
scope for this series.  (And I'm not sure it would be worth the hassle.)
  diff: factor out match_func_rec()
  diff: handle appended chunks better with -W
  diff: ignore empty lines before added functions with -W
  diff: don't include common trailing empty lines with -W
  grep: don't extend context to trailing empty lines with -W
 grep.c        | 28 ++++++++++++++++++++++++--
 xdiff/xemit.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 82 insertions(+), 9 deletions(-)
Previous: René ScharfeNext: René Scharfe
Message 4 of 27 in “[Bug?] log -p -W showing the whole file for a patch that adds to the end?”
  1. Junio C HamanoMay 10, 2016
  2. Junio C HamanoMay 10, 2016
  3. René ScharfeMay 12, 2016
  4. René ScharfeMay 21, 2016
  5. 1/5 diff: factor out match_func_rec()René Scharfe, May 21, 2016
  6. 2/5 diff: handle appended chunks better with -WRené Scharfe, May 21, 2016
  7. 3/5 diff: ignore empty lines before added functions with -WRené Scharfe, May 21, 2016
  8. 4/5 diff: don't include common trailing empty lines with -WRené Scharfe, May 21, 2016
  9. 5/5 grep: don't extend context to trailing empty lines with -WRené Scharfe, May 21, 2016
  10. Junio C HamanoMay 24, 2016
  11. René ScharfeMay 26, 2016
  12. Junio C HamanoMay 26, 2016
  13. René ScharfeMay 27, 2016
  14. René ScharfeMay 28, 2016
  15. 1/8 t4051: rewrite, add more testsRené Scharfe, May 28, 2016
  16. Junio C HamanoMay 29, 2016
  17. René ScharfeMay 30, 2016
  18. 1/8 t4051: rewrite, add more testsRené Scharfe, May 31, 2016
  19. René ScharfeMay 31, 2016
  20. Junio C HamanoMay 31, 2016
  21. 2/8 xdiff: factor out match_func_rec()René Scharfe, May 28, 2016
  22. 3/8 xdiff: handle appended chunks better with -WRené Scharfe, May 28, 2016
  23. 4/8 xdiff: ignore empty lines before added functions with -WRené Scharfe, May 28, 2016
  24. 5/8 xdiff: -W: don't include common trailing empty lines in contextRené Scharfe, May 28, 2016
  25. 6/8 xdiff: don't trim common tail with -WRené Scharfe, May 28, 2016
  26. 7/8 t7810: add test for grep -W and trailing empty context linesRené Scharfe, May 28, 2016
  27. 8/8 grep: -W: don't extend context to trailing empty linesRené Scharfe, May 28, 2016

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.