[PATCH RFC] util: make str(url) return file:/// for abs paths again
Matt Mackall
mpm at selenic.com
Thu May 12 18:48:56 CDT 2011
On Thu, 2011-05-12 at 16:47 +0200, Peter Arrenbrecht wrote:
> # HG changeset patch
> # User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
> # Date 1305211316 -7200
> # Node ID 9648ca19f5c98758ac76e2ef90d7aca773ee9763
> # Parent 2daa5179e73fdbf7bd0acbbc2ffc8f30d54d679b
> util: make str(url) return file:/// for abs paths again
>
> str(url) was recently changed to return only file:/. However, the canonical way to represent
> absolute local paths is file:/// [1], which is also expected by at least hgsubversion.
>
> Relative paths are returned as file:the/relative/path.
>
> [1] http://en.wikipedia.org/wiki/File_URI_scheme
Ok, I've gone and read the relevant RFCs and convinced myself that
file:/// is the canonical format. We'll continue to accept file:/, but
it'll get promoted on output. Queued, thanks.
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1500,6 +1500,8 @@
> 'bundle:../foo'
> >>> str(url('path'))
> 'path'
> + >>> str(url('file:///tmp/foo/bar'))
> + 'file:///tmp/foo/bar'
> >>> print url(r'bundle:foo\bar')
> bundle:foo\bar
> """
> @@ -1512,8 +1514,9 @@
> return s
>
> s = self.scheme + ':'
> - if (self.user or self.passwd or self.host or
> - self.scheme and not self.path):
> + if self.user or self.passwd or self.host:
> + s += '//'
> + elif self.scheme and (not self.path or self.path.startswith('/')):
> s += '//'
> if self.user:
> s += urllib.quote(self.user, safe=self._safechars)
> diff --git a/tests/test-url.py b/tests/test-url.py
> --- a/tests/test-url.py
> +++ b/tests/test-url.py
> @@ -191,11 +191,23 @@
> >>> str(u)
> 'http://foo/bar'
>
> + >>> u = url('file:/foo/bar/baz')
> + >>> u
> + <url scheme: 'file', path: '/foo/bar/baz'>
> + >>> str(u)
> + 'file:///foo/bar/baz'
> +
> >>> u = url('file:///foo/bar/baz')
> >>> u
> <url scheme: 'file', path: '/foo/bar/baz'>
> >>> str(u)
> - 'file:/foo/bar/baz'
> + 'file:///foo/bar/baz'
> +
> + >>> u = url('file:foo/bar/baz')
> + >>> u
> + <url scheme: 'file', path: 'foo/bar/baz'>
> + >>> str(u)
> + 'file:foo/bar/baz'
> """
>
> doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list