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

Re: [BUG-ish] diff compaction heuristic false positive

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jun 10, 2016, 11:00 UTC
Message-ID
<575A9DE5.2020401@alum.mit.edu>
In-Reply-To
<20160610084149.GA14592@sigill.intra.peff.net>
On 06/10/2016 10:41 AM, Jeff King wrote:
Show 56 quoted lines
> On Fri, Jun 10, 2016 at 10:31:13AM +0200, Michael Haggerty wrote:
> 
>> I've often thought that indentation would be a good, fairly universal
>> signal for diff to use when deciding how to slide hunks around. Most
>> source code is indented in a way that shows its structure.
>>
>> I propose the following heuristic:
>>
>> * Prefer to start and end hunks following lines with the least
>>   indentation.
>>
>> * Define the "indentation" of a blank line to be the indentation of
>>   the previous non-blank line minus epsilon.
>>
>> * In the case of a tie, prefer to slide the hunk down as far as
>>   possible.
> 
> Hmm. That might help this case, but the original motivation for this
> heuristic was something like:
> 
>   ##
>   # foo
>   def foo
>     something
>   end
> 
>   ##
>   # bar
>   def bar
>     something_else
>   end
> 
> where we add the first function above the second. We end up with:
> 
> diff --git a/file.rb b/file.rb
> index 1f9b151..f991c76 100644
> --- a/file.rb
> +++ b/file.rb
> @@ -1,4 +1,10 @@
>  ##
> +# foo
> +def foo
> +  something
> +end
> +
> +##
>  # bar
>  def bar
>    something else
> 
> I.e., crediting the "##" to the wrong spot (or in C, the "/*"). I don't
> think indentation helps us there (sliding-up would, but like
> sliding-down, it just depends on the order of the hunks).
> 
> So I agree that adding indentation to the mix might help, but I don't
> think it can replace this heuristic.

Ummm, I think the indentation heuristic would work with that example, too, as long as we consider there to be an imaginary line "0" of the file (i.e., preceding the first real line) that has an indentation of -ε.

Michael
Previous: Jeff King
Message 16 of 16 in “[BUG-ish] diff compaction heuristic false positive”
  1. Jeff KingJun 10, 2016
  2. Jeff KingJun 10, 2016
  3. Junio C HamanoJun 10, 2016
  4. Stefan BellerJun 10, 2016
  5. Jacob KellerJun 10, 2016
  6. Re* [BUG-ish] diff compaction heuristic false positiveJunio C Hamano, Jun 10, 2016
  7. Stefan BellerJun 10, 2016
  8. Jeff KingJun 10, 2016
  9. diff: disable compaction heuristic for nowJunio C Hamano, Jun 10, 2016
  10. Jeff KingJun 10, 2016
  11. Junio C HamanoJun 10, 2016
  12. Jeff KingJun 10, 2016
  13. Junio C HamanoJun 10, 2016
  14. Michael HaggertyJun 10, 2016
  15. Jeff KingJun 10, 2016
  16. Michael HaggertyJun 10, 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.