Follow-up to r2512, trying to, you know, get that change right this

time.

* lib/vclib/svn/__init__.py
  (_canonicalize_path): New helper function.
  (canonicalize_rootpath): Rework this to perform the URL -> absolute
    path conversion any time it can, not only when using really old
    Subversion versions.


git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@2735 8cb11bc2-c004-0410-86c3-e597b4017df7
trunk
cmpilato 2012-02-07 21:10:04 +00:00
parent 1b63870590
commit 23714979e4
1 changed files with 38 additions and 23 deletions

View File

@ -19,31 +19,46 @@ import urllib
_re_url = re.compile('^(http|https|file|svn|svn\+[^:]+)://')
def canonicalize_rootpath(rootpath):
### TODO: This feels ... wrong. We only try to convert the URL to
### a local path if we fail to call svn_path_canonicalize()?
### Really? Something tells me I goofed this logic up at some
### point. --cmpilato
def _canonicalize_path(path):
import svn.core
try:
import svn.core
return svn.core.svn_path_canonicalize(rootpath)
except:
if os.name == 'posix':
rootpath_lower = rootpath.lower()
if rootpath_lower in ['file://localhost',
'file://localhost/',
'file://',
'file:///'
]:
return '/'
if rootpath_lower.startswith('file://localhost/'):
return os.path.normpath(urllib.unquote(rootpath[16:]))
elif rootpath_lower.startswith('file:///'):
return os.path.normpath(urllib.unquote(rootpath[7:]))
if re.search(_re_url, rootpath):
return rootpath.rstrip('/')
return svn.core.svn_path_canonicalize(path)
except AttributeError: # svn_path_canonicalize() appeared in 1.4.0 bindings
# There's so much more that we *could* do here, but if we're
# here at all its because there's a really old Subversion in
# place, and those older Subversion versions cared quite a bit
# less about the specifics of path canonicalization.
if re.search(_re_url, path):
return path.rstrip('/')
else:
return os.path.normpath(path)
def canonicalize_rootpath(rootpath):
# Try to canonicalize the rootpath using Subversion semantics.
rootpath = _canonicalize_path(rootpath)
# ViewVC's support for local repositories is more complete and more
# performant than its support for remote ones, so if we're on a
# Unix-y system and we have a file:/// URL, convert it to a local
# path instead.
if os.name == 'posix':
rootpath_lower = rootpath.lower()
if rootpath_lower in ['file://localhost',
'file://localhost/',
'file://',
'file:///'
]:
return '/'
if rootpath_lower.startswith('file://localhost/'):
rootpath = os.path.normpath(urllib.unquote(rootpath[16:]))
elif rootpath_lower.startswith('file:///'):
rootpath = os.path.normpath(urllib.unquote(rootpath[7:]))
# Ensure that we have an absolute path (or URL), and return.
if not re.search(_re_url, rootpath):
assert os.path.isabs(rootpath)
return os.path.normpath(rootpath)
return rootpath
def expand_root_parent(parent_path):