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

Re: [PATCH 7/7] diff-highlight: detect --graph by indent

From
Jeff King <peff@peff.net>
Date
Mar 22, 2018, 11:18 UTC
Message-ID
<20180322111826.GA22763@sigill.intra.peff.net>
In-Reply-To
<0e2317fc-cfec-ba7f-8ded-59cc6b7f9a63@talktalk.net>
On Thu, Mar 22, 2018 at 10:59:31AM +0000, Phillip Wood wrote:
Show 14 quoted lines
> > +sub handle_line {
> > +	my $orig = shift;
> > +	local $_ = $orig;
> > +
> > +	# match a graph line that begins a commit
> > +	if (/^(?:$COLOR?\|$COLOR?[ ])* # zero or more leading "|" with space
> > +	         $COLOR?\*$COLOR?[ ]   # a "*" with its trailing space
> > +	      (?:$COLOR?\|$COLOR?[ ])* # zero or more trailing "|"
> > +	                         [ ]*  # trailing whitespace for merges
> 
> Hi Peff, thanks for looking at this. I've only had a quick look through
> but I wonder if this will be confused by commit messages that contain
>   * bullet points
>   * like this

I think we should be OK because the commit messages are indented by 4 spaces, and we allow only single spaces amidst the graph-drawing bits (and we respect the "*" only in those graph-drawing bits).

So I think you could fool it with something like:
  git log --graph --format='* oops!'
or maybe even:
  git log --graph --format='%B'

but not with a regular git-log format. Those final corner cases I don't think we can overcome; it's just syntactically ambiguous. Unless perhaps we traced the graph lines from the start of the output and knew how many to expect, but that seems rather complicated.

Ultimately the best solution would be to avoid this parsing nonsense entirely by teaching Git's internal diff to produce the highlighting internally.

-Peff
PS I also eyeballed the results of "git log --graph -p --no-merges
  -1000" piped through the old and new versions. There are several
  changes, but they all look like improvements.
Previous: Phillip WoodNext: Junio C Hamano
Message 14 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.