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

Re: [PATCHv3] diff.c: emit moved lines with a different color

From
Jacob Keller <jacob.keller@gmail.com>
Date
Sep 6, 2016, 06:58 UTC
Message-ID
<CA+P7+xo9KqnjajkPbP9_Q2H6hHT47dqPX9i3e5hvm28a0JWJOQ@mail.gmail.com>
In-Reply-To
<CAGZ79ka7VV6Pqw-rcVFv0xU4J4D9dHWPg-oocPPWJdY5JVhT+A@mail.gmail.com>
On Mon, Sep 5, 2016 at 7:20 PM, Stefan Beller <sbeller@google.com> wrote:
Show 31 quoted lines
>> If I understand, this is to ensure that we don't keep re-hashing each
>> line right?
>
> No, this is to ensure we have the context sensitivity of one prior line.
>
> In the collection phase we look at each line of the patch and make a hash of it.
> Then we store the hash temporarily (think of a state machine that goes line by
> line and always keeps the hash of the last line)
>
> What we store in the hashmaps is the hash(current line) ^
> hash(previous applicable line).
> With previous applicable line I mean any line starting with " " or "+"
> when the current
> line starts with "+" and " " or "-" when the current line starts with "-".
>
> When going through the second pass and actually emitting colored lines
> we only find matches in the hash map if the current line AND the previous line
> match as we lookup by hash code, i.e. if we have a moved line, but the
> previous line
> changed we do not find it in the hashmap and we don't color it, such
> that the reviewer
> can spot a permutation.
>
> So in the second phase we also need to have access to previous line, so maybe
> we could also go with just taking the line with us instead of 2 hash codes.
> But that implementation detail seems like a trade off to me, where I'd lean
> on keeping the hashes around as lines may be very long in bad cases, whereas
> the hashcode is short and it is a cheap hash.
>
> (I am referring to http://i.imgur.com/MnaSZ1D.png where in the malicious
> case all lines were moved to there as well, but permutated)

Good that clears up a lot of my questions. It seems like a reasonable algorithm, and I like the example of per-muted lines.

I think if we can find some real-world data on how much slower this is, we can find out what kind of configuration we want to give it? It seems like something incredibly helpful to me, but having a way out is nice incase it ends up being too costly. I suspect that will only be the case for a large patch.

Thanks, Jake

Previous: Stefan BellerNext: Junio C Hamano
Message 4 of 7 in “[PATCHv3] diff.c: emit moved lines with a different color”
  1. Stefan BellerSep 4, 2016
  2. Jacob KellerSep 6, 2016
  3. Stefan BellerSep 6, 2016
  4. Jacob KellerSep 6, 2016
  5. Junio C HamanoSep 7, 2016
  6. Stefan BellerSep 7, 2016
  7. Jacob KellerSep 7, 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.