comparison mercurial/util.py @ 15609:8f4bad72d8b1 stable

util: fix url.__str__() for windows file URLs Before: >>> str(url('file:///c:/tmp/foo/bar')) 'file:c%3C/tmp/foo/bar' After: >>> str(url('file:///c:/tmp/foo/bar')) 'file:///c%3C/tmp/foo/bar' The previous behaviour had no effect on mercurial itself (clone command for instance) because we fortunately called .localpath() on the parsed URL. hgsubversion was not so lucky and cloning a local subversion repository on Windows no longer worked on the default branch (it works on stable because de7e2fba4326 defeats the hasdriveletter() test in url class). I do not know if the %3C is correct or not but svn accepts file:// URLs containing it. Mads fixed it in de7e2fba4326, so we can always backport should the need arise.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 04 Dec 2011 18:22:25 +0100
parents ae04af1ce78d
children ec8a49c46d7e eacfd851cb9e
comparison
equal deleted inserted replaced
15608:63ff8fe3a8f0 15609:8f4bad72d8b1
1627 'bundle:../foo' 1627 'bundle:../foo'
1628 >>> str(url('path')) 1628 >>> str(url('path'))
1629 'path' 1629 'path'
1630 >>> str(url('file:///tmp/foo/bar')) 1630 >>> str(url('file:///tmp/foo/bar'))
1631 'file:///tmp/foo/bar' 1631 'file:///tmp/foo/bar'
1632 >>> str(url('file:///c:/tmp/foo/bar'))
1633 'file:///c%3A/tmp/foo/bar'
1632 >>> print url(r'bundle:foo\bar') 1634 >>> print url(r'bundle:foo\bar')
1633 bundle:foo\bar 1635 bundle:foo\bar
1634 """ 1636 """
1635 if self._localpath: 1637 if self._localpath:
1636 s = self.path 1638 s = self.path
1641 return s 1643 return s
1642 1644
1643 s = self.scheme + ':' 1645 s = self.scheme + ':'
1644 if self.user or self.passwd or self.host: 1646 if self.user or self.passwd or self.host:
1645 s += '//' 1647 s += '//'
1646 elif self.scheme and (not self.path or self.path.startswith('/')): 1648 elif self.scheme and (not self.path or self.path.startswith('/')
1649 or hasdriveletter(self.path)):
1647 s += '//' 1650 s += '//'
1651 if hasdriveletter(self.path):
1652 s += '/'
1648 if self.user: 1653 if self.user:
1649 s += urllib.quote(self.user, safe=self._safechars) 1654 s += urllib.quote(self.user, safe=self._safechars)
1650 if self.passwd: 1655 if self.passwd:
1651 s += ':' + urllib.quote(self.passwd, safe=self._safechars) 1656 s += ':' + urllib.quote(self.passwd, safe=self._safechars)
1652 if self.user or self.passwd: 1657 if self.user or self.passwd:
1714 1719
1715 def hasscheme(path): 1720 def hasscheme(path):
1716 return bool(url(path).scheme) 1721 return bool(url(path).scheme)
1717 1722
1718 def hasdriveletter(path): 1723 def hasdriveletter(path):
1719 return path[1:2] == ':' and path[0:1].isalpha() 1724 return path and path[1:2] == ':' and path[0:1].isalpha()
1720 1725
1721 def urllocalpath(path): 1726 def urllocalpath(path):
1722 return url(path, parsequery=False, parsefragment=False).localpath() 1727 return url(path, parsequery=False, parsefragment=False).localpath()
1723 1728
1724 def hidepassword(u): 1729 def hidepassword(u):