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

Re: [PATCH] diffcore-rename: favour identical basenames

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 22, 2007, 10:39 UTC
Message-ID
<Pine.LNX.4.64.0706221122200.4059@racer.site>
In-Reply-To
<467B777D.C47BFE0E@eudaptics.com>
Hi,
On Fri, 22 Jun 2007, Johannes Sixt wrote:
Show 12 quoted lines
> Johannes Schindelin wrote:
> >         The dangerous thing is that the score can get negative now.
> >  ...
> > +               score = (int)(src_copied * MAX_SCORE / max_size)
> > +                       - levenshtein(src->path, dst->path);
> 
> Does that also mean that you can't ever have a rename with a score of
> 100%?
> 
> (I haven't studied the algorithms and assume that levenshtein(a,b) == 0
> only if a==b, and that without the -levenshtein(...) the score can grow
> to 100%.)

There is a different code path for identical contents. So yes, you can still hit 100%, but it is now much, much harder to hit a score close to 100% [*1*].

The obviously correct way to do this is to have a subscore, and use it _strictly_ only when the score is identical.

I see two ways to do this properly:
- introduce a name_distance struct member, just below the score. This 
  means that estimate_similarity has to "return" two values instead of 
  one, and score_compare gets a bit more complex, too. Or
- change the score to unsigned long, and shift the score to higher bits, 
  adding a constant minus the Levenshtein distance. It is safe to assume 
  that the filenames are shorter than 16384 bytes (PATH_MAX is actually 
  much smaller than that), and even if two filenames of that length are 
  completely different, the distance can not be larger than twice that 
  number, i.e. 16384 deletions + 16384 insertions. Therefore, you could 
  pick 32768 as that constant.

However, I find both solutions ugly. Besides, I am not interested in the feature myself, only the implementation of Levenshtein was interesting, and I thought I just post the code here. So I did only the minimal stuff on top of the interesting one to make it sort of work.

If somebody wants to pick up the ball, be my guest, because I am out of that game.

Ciao, Dscho

Footnote:
*1* Actually, it is not _that_ bad. The score is not a value between 0 and 
    100, IOW it is _not_ what you see in the output of "diff -M". It is an 
    unsigned short between 0 and MAX_SCORE, which is defined in 
    diffcore.h as 60000.0.
    The Levenshtein distance between two filenames cannot be larger than 
    the sum of their lengths, so it should be relatively safe. That is, if 
    you don't have such insanely long paths as e.g. egit. But even there, 
    the paths share most of their directories, and therefore the distances 
    should be much, much smaller in real life.
Previous: Johannes SixtNext: David Kastrup
Message 31 of 44 in “Basename matching during rename/copy detection”
  1. Shawn O. PearceJun 21, 2007
  2. Junio C HamanoJun 21, 2007
  3. Andy ParkinsJun 21, 2007
  4. Junio C HamanoJun 21, 2007
  5. Andy ParkinsJun 21, 2007
  6. Johannes SchindelinJun 21, 2007
  7. Andy ParkinsJun 21, 2007
  8. Matthieu MoyJun 21, 2007
  9. Jeff KingJun 21, 2007
  10. Johannes SchindelinJun 21, 2007
  11. Matthieu MoyJun 21, 2007
  12. Johannes SchindelinJun 21, 2007
  13. Steven GrimmJun 21, 2007
  14. Johannes SchindelinJun 21, 2007
  15. Steven GrimmJun 21, 2007
  16. Johannes SchindelinJun 21, 2007
  17. Linus TorvaldsJun 21, 2007
  18. diffcore-rename: favour identical basenamesJohannes Schindelin, Jun 21, 2007
  19. Jeff KingJun 21, 2007
  20. Johannes SchindelinJun 21, 2007
  21. Linus TorvaldsJun 21, 2007
  22. Junio C HamanoJun 21, 2007
  23. Linus TorvaldsJun 21, 2007
  24. Andy ParkinsJun 22, 2007
  25. Johannes SchindelinJun 22, 2007
  26. Aidan Van DykJun 22, 2007
  27. Johannes SchindelinJun 22, 2007
  28. Jeff KingJun 22, 2007
  29. Johannes SchindelinJun 22, 2007
  30. Johannes SixtJun 22, 2007
  31. Johannes SchindelinJun 22, 2007
  32. 100% (was: [PATCH] diffcore-rename: favour identical basenames)David Kastrup, Jun 22, 2007
  33. Johannes SchindelinJun 22, 2007
  34. Junio C HamanoJun 23, 2007
  35. Johannes SchindelinJun 23, 2007
  36. René ScharfeJun 23, 2007
  37. Johannes SchindelinJun 23, 2007
  38. René ScharfeJun 23, 2007
  39. Johannes SchindelinJun 23, 2007
  40. René ScharfeJun 23, 2007
  41. Johannes SchindelinJun 23, 2007
  42. René ScharfeJun 24, 2007
  43. Junio C HamanoJun 23, 2007
  44. Johannes SchindelinJun 23, 2007

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.