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

Re: [PATCH 3/4] diff-highlight: match up lines before highlighting

From
Jeff King <peff@peff.net>
Date
Nov 3, 2015, 22:03 UTC
Message-ID
<20151103220314.GE22484@sigill.intra.peff.net>
In-Reply-To
<20151103214416.GC22484@sigill.intra.peff.net>
On Tue, Nov 03, 2015 at 04:44:16PM -0500, Jeff King wrote:
> Have you looked at a diff of the old/new output on something like
> git.git?
This should be pretty easy to do (and time). I tried:
  git log --oneline --color -p >base
  time perl highlight.old <base >old
  time perl highlight.new <base >new
  diff -c old new | less

where the "highlight.*" scripts are the versions at master, and master with your series applied.

Your is _much_ slower. I get:
  real    0m25.538s
  user    0m25.420s
  sys     0m0.120s
for the old versus:
  real    2m3.580s
  user    2m3.548s
  sys     0m0.156s

for your series. In an interactive setting, the latency may not be that noticeable, but if you are digging far into history (e.g., "git log -p", then using "/" in less to search for a commit or some test), I suspect it would be very noticeable.

I was thinking there was some low-hanging fruit in memoizing the calculations, but even the prefix/suffix computation is pairwise. I'm not really sure how to make this much faster.

As for the output itself, the diff between the two looks promising. The first several cases I looked at ar strict improvements. Some of them are kind of weird, especially in English text. For example, see the RelNotes update in 2635c2b. The base diff is:

    * "git rebase -i" had a minor regression recently, which stopped
    considering a line that begins with an indented '#' in its insn
-   sheet not a comment, which is now fixed.
-   (merge 1db168e gr/rebase-i-drop-warn later to maint).
+   sheet not a comment. Further, the code was still too picky on
+   Windows where CRLF left by the editor is turned into a trailing CR
+   on the line read via the "read" built-in command of bash.  Both of
+   these issues are now fixed.
+   (merge 39743cf gr/rebase-i-drop-warn later to maint).

Before we highlighted nothing, and now we hone in on "now fixed". Which is _sort of_ a match, but really the whole sentence structure has changed. If this is the worst regression, I can certainly live with it. And even a proper LCS diff would probably end up making spaghetti of a text change like this.

In the other thread I mentioned earlier, the solution I cooked up was dropping highlighting entirely for hunks over a certain percentage of highlighting. I wonder if we could do something similar here (e.g., don't match lines where more than 50% of the line would be highlighted).

-Peff
Previous: Jeff KingNext: Jonathan Lebon
Message 12 of 17 in “diff-highlight: make a few improvements”
  1. 0/4 diff-highlight: make a few improvementsJonathan Lebon, Nov 3, 2015
  2. 1/4 diff-highlight: add `less -r` to cmd in READMEJonathan Lebon, Nov 3, 2015
  3. Junio C HamanoNov 3, 2015
  4. Jonathan LebonNov 3, 2015
  5. Jeff KingNov 3, 2015
  6. Junio C HamanoNov 3, 2015
  7. Jeff KingNov 3, 2015
  8. 2/4 diff-highlight: factor out prefix/suffix functionsJonathan Lebon, Nov 3, 2015
  9. Jeff KingNov 3, 2015
  10. 3/4 diff-highlight: match up lines before highlightingJonathan Lebon, Nov 3, 2015
  11. Jeff KingNov 3, 2015
  12. Jeff KingNov 3, 2015
  13. Jonathan LebonNov 17, 2015
  14. Jeff KingNov 17, 2015
  15. 4/4 diff-highlight: add maxhunksize config optionJonathan Lebon, Nov 3, 2015
  16. Jeff KingNov 3, 2015
  17. Jeff KingNov 3, 2015

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.