[PATCH STABLE] url: really handle urls of the form file:///c:/foo/bar/ correctly

Mads Kiilerich mads at kiilerich.com
Wed Aug 3 19:53:50 CDT 2011


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1312419089 -7200
# Branch stable
# Node ID e89f62dcd723e7db5560939ad863ad426605afbf
# Parent  9991f8b19ff3fe353690646b2b2bb77e4db4981e
url: really handle urls of the form file:///c:/foo/bar/ correctly

28edd65000d9 made sure that paths that seemed to start with a windows drive
letter would not get an extra leading slash.

localpath should thus not try to handle this case by removing a leading slash,
and this special handling is thus removed.

(The localpath handling of this case was wrong anyway, because paths that look
like they start with a windows drive letter can't have a leading slash.)

A quick verification of this is to run 'hg id file:///c:/foo/bar/'.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1444,6 +1444,8 @@
                     path = None
                 if not self.host:
                     self.host = None
+                    # path of file:///d is /d
+                    # path of file:///d:/ is d:/, not /d:/
                     if path and not hasdriveletter(path):
                         path = '/' + path
 
@@ -1586,11 +1588,6 @@
                 path = self._hostport + '/' + self.path
             elif self.host is not None and self.path:
                 path = '/' + path
-            # We also need to handle the case of file:///C:/, which
-            # should return C:/, not /C:/.
-            elif hasdriveletter(path):
-                # Strip leading slash from paths with drive names
-                return path[1:]
             return path
         return self._origpath
 
diff --git a/tests/test-url.py b/tests/test-url.py
--- a/tests/test-url.py
+++ b/tests/test-url.py
@@ -204,18 +204,32 @@
     <url scheme: 'file', path: '/foo/bar/baz'>
     >>> str(u)
     'file:///foo/bar/baz'
+    >>> u.localpath()
+    '/foo/bar/baz'
 
     >>> u = url('file:///foo/bar/baz')
     >>> u
     <url scheme: 'file', path: '/foo/bar/baz'>
     >>> str(u)
     'file:///foo/bar/baz'
+    >>> u.localpath()
+    '/foo/bar/baz'
+
+    >>> u = url('file:///f:oo/bar/baz')
+    >>> u
+    <url scheme: 'file', path: 'f:oo/bar/baz'>
+    >>> str(u)
+    'file:f%3Aoo/bar/baz'
+    >>> u.localpath()
+    'f:oo/bar/baz'
 
     >>> u = url('file:foo/bar/baz')
     >>> u
     <url scheme: 'file', path: 'foo/bar/baz'>
     >>> str(u)
     'file:foo/bar/baz'
+    >>> u.localpath()
+    'foo/bar/baz'
     """
 
 doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)


More information about the Mercurial-devel mailing list