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

Re: [PATCH 6/7] Switch path canonicalization to use the SVN API.

From
EWEric Wong <normalperson@yhbt.net>
Date
Aug 2, 2012, 21:51 UTC
Message-ID
<20120802215141.GA5284@dcvr.yhbt.net>
In-Reply-To
<20120730200444.GB20137@dcvr.yhbt.net>
Eric Wong <normalperson@yhbt.net> wrote:
Show 28 quoted lines
> Michael G Schwern <schwern@pobox.com> wrote:
> > On 2012.7.28 6:55 AM, Jonathan Nieder wrote:
> > > Michael G. Schwern wrote:
> > >> --- a/perl/Git/SVN/Utils.pm
> > >> +++ b/perl/Git/SVN/Utils.pm
> > >> @@ -86,6 +86,27 @@ sub _collapse_dotdot {
> > >>  
> > >>  
> > >>  sub canonicalize_path {
> > >> +	my $path = shift;
> > >> +
> > >> +	# The 1.7 way to do it
> > >> +	if ( defined &SVN::_Core::svn_dirent_canonicalize ) {
> > >> +		$path = _collapse_dotdot($path);
> > >> +		return SVN::_Core::svn_dirent_canonicalize($path);
> > >> +	}
> > >> +	# The 1.6 way to do it
> > >> +	elsif ( defined &SVN::_Core::svn_path_canonicalize ) {
> > >> +		$path = _collapse_dotdot($path);
> > >> +		return SVN::_Core::svn_path_canonicalize($path);
> > >> +	}
> > >> +	# No SVN API canonicalization is available, do it ourselves
> > >> +	else {
> > > 
> > > When would this "else" case trip?
> > 
> > When svn_path_canonicalize() does not exist in the SVN API, presumably because
> > their SVN is too old.

svn_path_canonicalize() may be accessible in some versions of SVN, but it'll return undef.

I'm squashing the change below to have it fall back to _canonicalize_path_ourselves in the case svn_path_canonicalize() is present but unusable.

Show 14 quoted lines
> > > Would it be safe to make it
> > > return an error message, or even to do something like the following?
> > 
> > I don't know what your SVN backwards compat requirements are, or when
> > svn_path_canonicalize() appears in the API, so I left it as is.  git-svn's
> > home rolled path canonicalization worked and its no work to leave it working.
> >  No reason to break it IMO.
> 
> I agree there's no reason to break something on older SVN.
> 
> git-svn should work with whatever SVN is in CentOS 5.x and similar
> distros (SVN 1.4.2).  As long as an active "long-term" distro supports
> a version of SVN, I think we should support that if it's not too
> difficult.
I've tested the following on an old CentOS 5.2 chroot with SVN 1.4.2:
diff --git a/perl/Git/SVN/Utils.pm b/perl/Git/SVN/Utils.pm
index b7727db..4bb4dde 100644
--- a/perl/Git/SVN/Utils.pm
+++ b/perl/Git/SVN/Utils.pm
@@ -88,22 +88,25 @@ sub _collapse_dotdot {
 
 sub canonicalize_path {
 	my $path = shift;
+	my $rv;
 
 	# The 1.7 way to do it
 	if ( defined &SVN::_Core::svn_dirent_canonicalize ) {
 		$path = _collapse_dotdot($path);
-		return SVN::_Core::svn_dirent_canonicalize($path);
+		$rv = SVN::_Core::svn_dirent_canonicalize($path);
 	}
 	# The 1.6 way to do it
+	# This can return undef on subversion-perl-1.4.2-2.el5 (CentOS 5.2)
 	elsif ( defined &SVN::_Core::svn_path_canonicalize ) {
 		$path = _collapse_dotdot($path);
-		return SVN::_Core::svn_path_canonicalize($path);
-	}
-	# No SVN API canonicalization is available, do it ourselves
-	else {
-		$path = _canonicalize_path_ourselves($path);
-		return $path;
+		$rv = SVN::_Core::svn_path_canonicalize($path);
 	}
+
+	return $rv if defined $rv;
+
+	# No SVN API canonicalization is available, or the SVN API
+	# didn't return a successful result, do it ourselves
+	return _canonicalize_path_ourselves($path);
 }
 
 
-- 
Eric Wong
Previous: Eric WongNext: Michael G Schwern
Message 32 of 39 in “Canonicalize the git-svn path & url accessors”
  1. Michael G. SchwernJul 28, 2012
  2. 1/7 Move the canonicalization functions to Git::SVN::UtilsMichael G. Schwern, Jul 28, 2012
  3. 2/7 Change canonicalize_url() to use the SVN 1.7 API when available.Michael G. Schwern, Jul 28, 2012
  4. Jonathan NiederJul 28, 2012
  5. Michael G SchwernJul 28, 2012
  6. Jonathan NiederJul 28, 2012
  7. Michael G SchwernJul 28, 2012
  8. Jonathan NiederJul 28, 2012
  9. Jonathan NiederJul 28, 2012
  10. Michael G SchwernJul 28, 2012
  11. 0/2 Re: [PATCH 2/7] Change canonicalize_url() to use the SVN 1.7 API when available.Jonathan Nieder, Oct 14, 2012
  12. 1/2 git svn: do not overescape URLs (fallback case)Jonathan Nieder, Oct 14, 2012
  13. 2/2 git svn: canonicalize_url(): use svn_path_canonicalize when availableJonathan Nieder, Oct 14, 2012
  14. Eric WongOct 23, 2012
  15. 3/7 Extract, test and enhance the logic to collapse ../foo paths.Michael G. Schwern, Jul 28, 2012
  16. Eric WongJul 30, 2012
  17. Michael G SchwernJul 30, 2012
  18. Jonathan NiederSep 26, 2012
  19. Eric WongSep 26, 2012
  20. Jonathan NiederSep 26, 2012
  21. Eric WongSep 26, 2012
  22. Jonathan NiederSep 26, 2012
  23. Eric WongSep 27, 2012
  24. Jonathan NiederSep 27, 2012
  25. 4/7 Add join_paths() to safely concatenate paths.Michael G. Schwern, Jul 28, 2012
  26. Jonathan NiederSep 26, 2012
  27. 5/7 Remove irrelevant comment.Michael G. Schwern, Jul 28, 2012
  28. 6/7 Switch path canonicalization to use the SVN API.Michael G. Schwern, Jul 28, 2012
  29. Jonathan NiederJul 28, 2012
  30. Michael G SchwernJul 28, 2012
  31. Eric WongJul 30, 2012
  32. Eric WongAug 2, 2012
  33. Michael G SchwernAug 2, 2012
  34. git-svn: keep leading slash when canonicalizing paths (fallback case)Jonathan Nieder, Oct 5, 2012
  35. Eric WongOct 5, 2012
  36. Junio C HamanoOct 6, 2012
  37. 7/7 Make Git::SVN and Git::SVN::Ra canonicalize paths and urls.Michael G. Schwern, Jul 28, 2012
  38. Jonathan NiederJul 28, 2012
  39. Michael G SchwernJul 28, 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.