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

Re: [BUG] log --graph corrupts patch

From
Jeff King <peff@peff.net>
Date
Mar 20, 2018, 15:58 UTC
Message-ID
<20180320155814.GA32366@sigill.intra.peff.net>
In-Reply-To
<1e686ea0-90ac-f3f4-7bcf-6951c9253598@talktalk.net>
On Tue, Mar 20, 2018 at 09:58:14AM +0000, Phillip Wood wrote:
Show 6 quoted lines
> > Are you using any exotic filters for your pager? If you use "git
> > --no-pager" does the problem persist?
> 
> Hi Peff, thanks for taking the time to check this, I had forgotten about
> the pager. I'm using diff-highlight and it seems that is causing the
> problems.

Heh. Lucky guess. Unsurprisingly, I use diff-highlight, too. But I did not see it because I never bothered to upgrade my personal copy of the script, which has been working for me for ages, to the one in contrib/.

But indeed, I can easily reproduce the problem with that version of the script. Here's a pretty minimal reproduction:

-- >8 --
cat >bad <<\EOF
* commit whatever
| other stuff irrelevant
|
| diff --git a/foo b/foo
| --- a/foo
| --- b/foo
| @@ -100,6 +100,9
|  some
|  context
|  lines
| +some
| +new
| +lines
|  -context line with a leading minus
|  and other
|  context
EOF
contrib/diff-highlight/diff-highlight <bad
-- 8< --
which produce:
...
|  -context line with a leading minus
| +some
| +new
| +lines
...

The issue bisects to 7e4ffb4c17 (diff-highlight: add support for --graph output, 2016-08-29). I think the problem is the "\s+" at the end of the $GRAPH regex, which soaks up the space for the context, and accidentally treats the "-" line as a preimage removal.

But just switching that to "\s" doesn't quite work. We may have an arbitrary number of spaces between the graph ascii-art and the diff. E.g., if you have a commit at the base of a branch (the test in contrib/diff-highlight shows this case).

So I think you'd have to record the indent of the previous hunk header, and then make sure that the indent matched that. But even there, I think we're subject to false positives if a commit message contains a hunk header (it's indented an extra 4 characters, but we'd accidentally soak that up thinking it was graph indentation).

To make it bullet-proof, I think we'd have to actually parse the graph structure, finding a "*" line and then accepting only an indent that matched it.

-Peff
Previous: Phillip WoodNext: Jeff King
Message 4 of 15 in “[BUG] log --graph corrupts patch”
  1. Phillip WoodMar 19, 2018
  2. Jeff KingMar 20, 2018
  3. Phillip WoodMar 20, 2018
  4. Jeff KingMar 20, 2018
  5. Jeff KingMar 21, 2018
  6. 1/7 diff-highlight: correct test graph diagramJeff King, Mar 21, 2018
  7. 2/7 diff-highlight: use test_tick in graph testJeff King, Mar 21, 2018
  8. 3/7 diff-highlight: prefer "echo" to "cat" in testsJeff King, Mar 21, 2018
  9. 4/7 diff-highlight: test interleaved parallel lines of historyJeff King, Mar 21, 2018
  10. 5/7 diff-highlight: test graphs with --colorJeff King, Mar 21, 2018
  11. 6/7 diff-highlight: use flush() helper consistentlyJeff King, Mar 21, 2018
  12. 7/7 diff-highlight: detect --graph by indentJeff King, Mar 21, 2018
  13. Phillip WoodMar 22, 2018
  14. Jeff KingMar 22, 2018
  15. Junio C HamanoMar 21, 2018

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.