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

Re: Fix git-svn for SVN 1.7

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 31, 2012, 06:53 UTC
Message-ID
<7v1ujsl8ut.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120730203844.GA23892@dcvr.yhbt.net>
Eric Wong <normalperson@yhbt.net> writes:
Show 7 quoted lines
> Perhaps we can depend on the URI.pm module?  It seems to be
> widely-available and not be a significant barrier to installation.  On
> the other hand, I don't know its history, either (especially since we're
> now dealing with SVN changes...).
>
> Anyways, I don't like relying on operator overloading, it makes code
> harder to read and review.

I think code that uses operator overloading, when printed in a textbook, cast in stone and makes the reader aware that it is never going to change, is indeed "easy" to read through. But I suspect that it may be merely giving a false illusion that it is easy to readers.

The problem is that use of such obscure overloading tends to hurt maintainability. If the initial version Michael produces converts all the external strings into instances of CanonicalizedPath class, according to the "convert as early as possible" principle, you can be assured that all "eq" you see are about the normalized strings the svn library wants to see, and that may allow us sleep safely.

But the real problem begins six months down the road, when somebody wants to add a new codepath that reads a new string from an external source (e.g. perhaps you add a new configuration variable that specifies a path in the svn repository and does something special when that path is touched by a revision; the exact nature of the new feature does not matter in this discussion). The new code can forget to follow the "convert early" principle, and pass a bare string read from the configuration around.

A comparison between such a new string and another variable that holds path that comes from the existing codepath (i.e. Michael's initial code that perfectly follows the "convert early" principle) will still use the overloaded eq in "$new_str eq $old_path", thanks to the language rule of Perl (namely, even though the new string is a non object, the other side is still an instance of the class).

When the code needs to compare two or more such "new" strings (e.g. perhaps it wants to remove duplicates from the set of paths it reads from the configuration), however, "eq" silently turns back to a simple string comparison, as "$new_1 eq $new_2" will not magically turn into "Canonicalize($new_1)->cmp(Canonicalize($new_2))".

This kind of error is unnecessarily hard to catch mostly because the previous "$new_str eq $old_path" does work; it masks the problem. Overloading of "eq" is making it harder to spot new bugs.

If the code never uses "eq" to compare canonicalized paths, and all the surrounding code compare paths using explicit method call on objects, it makes it crystal clear to the readers that paths held in a bare string is unwelcome in the codepath. It makes it harder to add new code that uses and passes around a bare string by mistake to such a codepath, I would think.

Previous: Michael G SchwernNext: Michael G Schwern
Message 31 of 50 in “Fix git-svn for SVN 1.7”
  1. Michael G. SchwernJul 28, 2012
  2. 1/8 SVN 1.7 will truncate "not-a%40{0}" to just "not-a".Michael G. Schwern, Jul 28, 2012
  3. Jonathan NiederJul 28, 2012
  4. Michael G SchwernJul 28, 2012
  5. svn test: escape peg revision separator using empty peg revJonathan Nieder, Oct 9, 2012
  6. Michael J GruberOct 9, 2012
  7. Jonathan NiederOct 9, 2012
  8. Eric WongOct 10, 2012
  9. Jonathan NiederOct 10, 2012
  10. Eric WongOct 10, 2012
  11. Jonathan NiederOct 10, 2012
  12. Eric WongOct 10, 2012
  13. Junio C HamanoOct 10, 2012
  14. 2/8 Fix typo in testMichael G. Schwern, Jul 28, 2012
  15. 3/8 Improve our URL canonicalization to be more like SVN 1.7's.Michael G. Schwern, Jul 28, 2012
  16. 4/8 Replace hand rolled URL escapes with canonicalizationMichael G. Schwern, Jul 28, 2012
  17. 5/8 Canonicalize earlier in a couple spots.Michael G. Schwern, Jul 28, 2012
  18. 6/8 Add function to append a path to a URL.Michael G. Schwern, Jul 28, 2012
  19. 7/8 Turn on canonicalization on newly minted URLs.Michael G. Schwern, Jul 28, 2012
  20. test: work around SVN 1.7 mishandling of svn:special changesJonathan Nieder, Oct 6, 2012
  21. git svn: work around SVN 1.7 mishandling of svn:special changesJonathan Nieder, Oct 9, 2012
  22. Eric WongOct 10, 2012
  23. git svn: work around SVN 1.7 mishandling of svn:special changesJonathan Nieder, Oct 10, 2012
  24. 8/8 Remove some ad hoc canonicalizations.Michael G. Schwern, Jul 28, 2012
  25. Eric WongJul 30, 2012
  26. Michael G SchwernJul 30, 2012
  27. Eric WongJul 30, 2012
  28. Michael G SchwernJul 31, 2012
  29. Eric WongJul 31, 2012
  30. Michael G SchwernJul 31, 2012
  31. Junio C HamanoJul 31, 2012
  32. Michael G SchwernJul 31, 2012
  33. Eric WongJul 31, 2012
  34. Junio C HamanoJul 31, 2012
  35. Michael G SchwernJul 31, 2012
  36. Michael G SchwernJul 31, 2012
  37. Eric WongAug 1, 2012
  38. Eric WongAug 2, 2012
  39. Jonathan NiederAug 2, 2012
  40. Junio C HamanoAug 2, 2012
  41. Robin H. JohnsonAug 2, 2012
  42. Eric WongAug 2, 2012
  43. Junio C HamanoAug 21, 2012
  44. Eric WongAug 21, 2012
  45. Junio C HamanoAug 21, 2012
  46. Eric WongAug 2, 2012
  47. Junio C HamanoAug 2, 2012
  48. Eric WongAug 2, 2012
  49. Eric WongAug 2, 2012
  50. Junio C HamanoAug 2, 2012

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.