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

Re: [PATCH] diff compaction heuristic: favor shortest neighboring blank lines

From
Jeff King <peff@peff.net>
Date
Jun 17, 2016, 15:36 UTC
Message-ID
<20160617153637.GA9314@sigill.intra.peff.net>
In-Reply-To
<20160616174620.1011-1-sbeller@google.com>
On Thu, Jun 16, 2016 at 10:46:20AM -0700, Stefan Beller wrote:
Show 28 quoted lines
> The compaction heuristic for diffs was deemed quite good, but in 5580b27
> we have an example demonstrates a common case, that fails with the existing
> heuristic. That is why we disabled the heuristic in the v2.9.0 release.
> 
> With this patch a diff looks like:
> 
>          def bar
>                  do_bar_stuff()
> 
>                  common_ending()
>          end
> 
> +        def bal
> +                do_bal_stuff()
> +
> +                common_ending()
> +        end
> +
>          def baz
>                  do_baz_stuff()
> 
>                  common_ending()
>          end
> 
> whereas before we had:
> 
>   WIP (TODO: ask peff to provide an example that actually triggers, I seem to be
>        unable to write one, though I thought the above was one)

Did you want something that triggers the "bad" case with the existing compaction heuristic?

I gave one in:
  http://article.gmane.org/gmane.comp.version-control.git/296947

I think the difference is that in my example, the diff (before compaction) has the blank line at the top (because we are adding a new entry at the bottom), whereas in yours, the blank line is at the bottom.

This patch does make my "bad" case look better. Unfortunately, it re-breaks another case:

	cat >file.rb <<\EOF
	##
	# This is the foo function.
	def foo
	  foo stuff
	end
	##
	# This is the bar function.
	def bar
	  bar stuff
	end
	##
	# This is the baz function.
	def baz
	  baz stuff
	end
	EOF
	git init
	git add file.rb
	sed -i 7,12d file.rb
	git diff
That goes back to the original, pre-compaction-heuristic diff:
	diff --git a/file.rb b/file.rb
	index 0b31fb6..ee25d63 100644
	--- a/file.rb
	+++ b/file.rb
	@@ -5,12 +5,6 @@ def foo
	 end
	 
	 ##
	-# This is the bar function.
	-def bar
	-  bar stuff
	-end
	-
	-##
	 # This is the baz function.
	 def baz
	   baz stuff
-Peff
Previous: Stefan BellerNext: Stefan Beller
Message 6 of 15 in “diff compaction heuristic: favor shortest neighboring blank lines”
  1. diff compaction heuristic: favor shortest neighboring blank linesStefan Beller, Jun 16, 2016
  2. Junio C HamanoJun 16, 2016
  3. Stefan BellerJun 16, 2016
  4. Michael HaggertyJun 16, 2016
  5. Stefan BellerJun 16, 2016
  6. Jeff KingJun 17, 2016
  7. Stefan BellerJun 17, 2016
  8. Michael HaggertyJun 23, 2016
  9. Stefan BellerJun 23, 2016
  10. Junio C HamanoJun 23, 2016
  11. Michael HaggertyJun 23, 2016
  12. Michael HaggertyJun 30, 2016
  13. diff heuristics dramatically improved by considering line indentation and blank linesMichael Haggerty, Jul 1, 2016
  14. Junio C HamanoJul 1, 2016
  15. Jakub NarębskiJul 4, 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.