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

Re: [PATCH] Fix -B "very-different" logic.

From
Junio C Hamano <junkio@cox.net>
Date
Jun 3, 2005, 01:33 UTC
Message-ID
<7vis0wusv5.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.58.0506021716140.1876@ppc970.osdl.org>
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:
LT> Careful. 

LT> I think the amount of new code _should_ matter. Otherwise, an old empty LT> file would always be considered the source of a new file, since the diff LT> doesn't remove anything. Similarly, just because we have a boilerplate LT> file shouldn't make that always be considered a "wonderful source", when LT> people add the real meat to it.

Yes, I agree that rename/copy logic should use different heuristics from the one I proposed for breaking.

It is my assumption that people in practice tend to make only small edits after a rename/copy just to adjust things like:

 - filenames mentioned in the comment of the file itself,
 - include paths that refer other files if the file was
   moved/copied from a different directory,
 - names of functions and variables.

and making sure there would not be too much new stuff is quite useful to detect rename/copy source correctly as the current similarity estimator in diffcore-rename does. I do not intend to touch that.

The boilderplate example you mention is a very good reason not to dismiss the amount of new material when doing rename/copy detection.

LT> In particular, let's say that I used to have two files:

LT> a.c - small helper functions LT> b.c - the "meat" of the thing

LT> and I end up deciding that I might as well collapse it all into one file, LT> a.c. What happens? There's almost no deletes from a.c, but there's a lot LT> of new code in it.

LT> See what I'm saying?
Yes.  I think I do.

When git-diff-tree -B -C runs your example, it feeds diffcore with these:

  :100644 100644 sha1-a-helper-only sha1-a-and-meat M   a.c
  :100644 000000 sha1-b-stale-meat  0{40}           D   b.c

The ideal diffcore-break breaks a.c because it looks at insertions as well:

  :100644 000000 sha1-a-helper-only 0{40}           D   a.c
  :000000 100644 0{40}              sha1-a-and-meat N   a.c
  :100644 000000 sha1-b-stale-meat  0{40}           D   b.c

Then diffcore-rename notices that sha1-b-stale-meat is better match than sha1-a-helper-only to produce sha1-a-and-meat, and resolves the above to:

  :100644 100644 sha1-b-stale-meat  sha1-a-and-meat R   b.c	a.c
Up to this point is just a demonstration that I see your point.

But I still want to keep the example I gave in the original commit message. Suppose you did not have b.c file under version control, and did the same operation. I.e. a.c acquired a lot of good stuff. git-diff-tree -B -C feeds:

  :100644 100644 sha1-a-helper-only sha1-a-and-meat M   a.c
which is broken into:
  :100644 000000 sha1-a-helper-only 0{40}           D   a.c
  :000000 100644 0{40}              sha1-a-and-meat N   a.c

Unfortunately, in this case nobody absorbs these pairs. I want to allow you to add 1000 lines of new stuff to a file (which was originally 100 lines long) as long as you do not remove too many lines from the original 100 lines without triggering "this is a rewrite" logic in this case. So after rename/copy runs, we need to match these up and merge them back into the original.

  :100644 100644 sha1-a-helper-only sha1-a-and-meat M   a.c

We should carry a bit more information about broken entries than we currently do. We would break a pair based on both deletion and insertion, just like the current code (i.e. without the patch you are responding to) does. But when we do break a pair, we need to mark them if the "new" side have enough original source material remaining. If we have such mark to tell us that "these were broken but there are a good chunk of source material remaining", the clean-up phase, to run after diffcore-rename finishes, should be able to notice surviving broken pairs and merge them back accordingly.

Previous: Linus TorvaldsNext: Junio C Hamano
Message 35 of 64 in “I want to release a "git-1.0"”
  1. Linus TorvaldsMay 30, 2005
  2. jeff millarMay 30, 2005
  3. Nicolas PitreMay 30, 2005
  4. Junio C HamanoJun 1, 2005
  5. Add -d flag to git-pull-* family.Junio C Hamano, Jun 1, 2005
  6. Nicolas PitreJun 1, 2005
  7. Junio C HamanoJun 1, 2005
  8. Junio C HamanoMay 30, 2005
  9. Junio C HamanoMay 30, 2005
  10. David GreavesMay 30, 2005
  11. Dave JonesMay 30, 2005
  12. Dmitry TorokhovMay 30, 2005
  13. Junio C HamanoMay 30, 2005
  14. Dmitry TorokhovMay 30, 2005
  15. Linus TorvaldsMay 31, 2005
  16. Ryan AndersonMay 30, 2005
  17. Linus TorvaldsMay 31, 2005
  18. Chris WedgwoodMay 30, 2005
  19. Chris WedgwoodMay 30, 2005
  20. Linus TorvaldsMay 31, 2005
  21. Junio C HamanoJun 1, 2005
  22. David LangJun 1, 2005
  23. Junio C HamanoJun 1, 2005
  24. David LangJun 1, 2005
  25. C. Scott AnanianJun 1, 2005
  26. Nicolas PitreJun 2, 2005
  27. Brian O'MahoneyJun 2, 2005
  28. Junio C HamanoJun 1, 2005
  29. Petr BaudisMay 31, 2005
  30. Eric W. BiedermanMay 31, 2005
  31. Linus TorvaldsJun 1, 2005
  32. Junio C HamanoJun 1, 2005
  33. Fix -B "very-different" logic.Junio C Hamano, Jun 2, 2005
  34. Linus TorvaldsJun 3, 2005
  35. Junio C HamanoJun 3, 2005
  36. 0/4 Fix -B "very-different" logic.Junio C Hamano, Jun 3, 2005
  37. 1/4 Tweak count-delta interfaceJunio C Hamano, Jun 3, 2005
  38. 2/4 diff: Fix docs and add -O to diff-helper.Junio C Hamano, Jun 3, 2005
  39. 3/4 diff: Clean up diff_scoreopt_parse().Junio C Hamano, Jun 3, 2005
  40. 4/4 diff: Update -B heuristics.Junio C Hamano, Jun 3, 2005
  41. Junio C HamanoJun 1, 2005
  42. Daniel BarkalowJun 1, 2005
  43. Junio C HamanoJun 1, 2005
  44. Petr BaudisJun 3, 2005
  45. Daniel BarkalowJun 3, 2005
  46. Eric W. BiedermanJun 2, 2005
  47. Kay SieversJun 2, 2005
  48. Linus TorvaldsJun 2, 2005
  49. several typos in tutorialAlexey Nezhdanov, Jun 2, 2005
  50. Vincent HanquezJun 2, 2005
  51. Alexey NezhdanovJun 2, 2005
  52. Vincent HanquezJun 2, 2005
  53. Alexey NezhdanovJun 2, 2005
  54. Alexey NezhdanovJun 2, 2005
  55. Adam KropelinJun 2, 2005
  56. Linus TorvaldsJun 3, 2005
  57. Linus TorvaldsJun 3, 2005
  58. Adam KropelinJun 3, 2005
  59. CVS migration section to the tutorial.Junio C Hamano, Jun 2, 2005
  60. Nicolas PitreJun 2, 2005
  61. Nicolas PitreJun 2, 2005
  62. Junio C HamanoJun 2, 2005
  63. Linus TorvaldsJun 2, 2005
  64. Junio C HamanoJun 2, 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.