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

Re: Delitifier broken (Re: diff-core segfault)

From
Linus Torvalds <torvalds@osdl.org>
Date
Dec 13, 2005, 01:34 UTC
Message-ID
<Pine.LNX.4.64.0512121720150.15597@g5.osdl.org>
In-Reply-To
<7vlkypdcsb.fsf@assigned-by-dhcp.cox.net>
On Mon, 12 Dec 2005, Junio C Hamano wrote:
Show 6 quoted lines
> 
> I'll revert the changes anyway, but not because I necessarily
> agree with you two.  I am not 100% confident that the core of
> the diff_delta code would work fine with empty input (it seems
> to from my limited test), and I do not want to break things
> unnecessarily at this point.

Well, I checked the pack-objects.c side, and your patch to diff_delta() should not hurt at least there. We already check the size and would have broken out long before if either side was zero-sized.

But that's kind of part of the point - any user of diff_delta() is likely to have checked the size anyway for other reasons. There's just very seldom any valid reason to generate a delta against an empty file, there's no interesting information that diff_delta() can really give us.

Basically, the binary diffs that diff-delta returns are interesting for just two things:

 - efficient packing, in the pack-objects.c style.
   As mentioned, pack-objects.c needs to check the size heuristics before 
   doing diff_delta() _anyway_, for performance reasons as well as simply 
   because the secondary use of diff_delta() is to estimate how big the 
   delta is, and it's always pointless to generate a delta that is 
   guaranteed to be bigger than the file (which is always the case with 
   either side being an empty file - the size difference will inevitably 
   be bigger than the size of the resulting file).
 - difference size estimation (ie for rename/copy detection)
   This boils down to the same case as the secondary use of pack-objects, 
   ie delta size estimation. Again, if either side is empty, we _know_ 
   that the delta generation is pointless, because the delta is always 
   going to be bigger than the end result, and thus it can't be sensible 
   for rename/copy detection.

So in one sense I actually agree with your patch: it makes the deltifier code more generic and actually simplifies the diff_delta() code a bit by avoiding one special case, and in that sense it's a good change.

So the reason I disagree with it is that doing the delta is always going to be unnecessary work. And regardless of how we're ever going to use the delta, we _know_ that it's unnecessary work.

So I think your diffcore-break.c patch is much more appropriate: it also fixes the bug, but it fixes it by virtue of realizing that the delta cannot matter and thus should never even be computed.

Now, your diff_setup() change may actually be worth it because of the simplification, but on the other hand, you can also consider the NULL return as being nice because it's effectively a way of saying "the delta is meaningless, why did you even ask me?"

			Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 15 in “diff-core segfault”
  1. Darrin ThompsonDec 12, 2005
  2. Johannes SchindelinDec 12, 2005
  3. Junio C HamanoDec 12, 2005
  4. Delitifier broken (Re: diff-core segfault)Junio C Hamano, Dec 12, 2005
  5. Nicolas PitreDec 12, 2005
  6. Junio C HamanoDec 12, 2005
  7. Linus TorvaldsDec 12, 2005
  8. Junio C HamanoDec 13, 2005
  9. Linus TorvaldsDec 13, 2005
  10. Junio C HamanoDec 13, 2005
  11. Linus TorvaldsDec 13, 2005
  12. Nicolas PitreDec 13, 2005
  13. Junio C HamanoDec 13, 2005
  14. 2/2 diff-delta.c: allow delta with empty blob.Junio C Hamano, Dec 12, 2005
  15. Darrin ThompsonDec 12, 2005

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.