[PATCH] url: do not encode backslash in local paths (fixes 4e8f2310f310)

Matt Mackall mpm at selenic.com
Wed Mar 30 06:54:10 CDT 2011


On Wed, 2011-03-30 at 10:23 +0200, Adrian Buehlmann wrote:
> On 2011-03-29 03:00, Brodie Rao wrote:
> > On Mon, Mar 28, 2011 at 12:53 AM, Adrian Buehlmann <adrian at cadifra.com> wrote:
> >> # HG changeset patch
> >> # User Adrian Buehlmann <adrian at cadifra.com>
> >> # Date 1301296930 -7200
> >> # Node ID 8f230f54126411b558125f064b3cd8f9d50f404d
> >> # Parent  46c3043253fbd4f54bed61c4cdda2a2c198e622f
> >> url: do not encode backslash in local paths (fixes 4e8f2310f310)
> >>
> >> It's the canonical path separator on Windows.
> >>
> >> BEFORE:
> >>  $ hg out
> >>  comparing with C:%5CUsers%5Cadi%5Chgrepos%5Ctests%5Ca
> >>  searching for changes
> >>  no changes found
> >>
> >> AFTER:
> >>  $ hg out
> >>  comparing with C:\Users\adi\hgrepos\tests\a
> >>  searching for changes
> >>  no changes found
> >>
> >> diff --git a/mercurial/url.py b/mercurial/url.py
> >> --- a/mercurial/url.py
> >> +++ b/mercurial/url.py
> >> @@ -56,7 +56,7 @@ class url(object):
> >>     """
> >>
> >>     _safechars = "!~*'()+"
> >> -    _safepchars = "/!~*'()+"
> >> +    _safepchars = "\\/!~*'()+"
> > 
> > I don't think this is enough. The data in the url object is still wrong:
> > 
> >>>> url(r'C:\foo')
> > <url scheme: 'C', path: '\\foo'>
> > 
> > We should try to detect the drive letter when parsing the scheme out.
> > We can do this just when os.name == 'nt'. It should do the same test
> > that localpath() does and that drop_scheme() did.
> > 
> >>     def __init__(self, path, parse_query=True, parse_fragment=True):
> >>         # We slowly chomp away at path until we have only the path left
> 
> Ok. So 4e8f2310f310 broke the default branch quite thoroughly on
> Windows. And my fix is "not enough", because it apparently doesn't fix
> the current breakage on the default branch completely.


> Could 4e8f2310f310 and friends be backed out until this has been sorted
> out? It seems these patches were pushed a bit prematurely.

That cset adds a bunch of code with no users.

How about something like this:

diff -r 307c72686eb0 mercurial/url.py
--- a/mercurial/url.py	Mon Mar 28 11:18:56 2011 -0500
+++ b/mercurial/url.py	Wed Mar 30 06:53:52 2011 -0500
@@ -39,6 +39,8 @@
     <url scheme: 'file', path: '/home/joe/repo'>
     >>> url('bundle:foo')
     <url scheme: 'bundle', path: 'foo'>
+    >>> url('c:\\foo\\bar')
+    <url path: 'c:\\foo\\bar'>
 
     Authentication credentials:
 
@@ -64,6 +66,11 @@
         self.port = self.path = self.query = self.fragment = None
         self._localpath = True
 
+        # special case for Windows drive letters
+        if path[1:2] == ':':
+            self.path = path
+            return
+
         if not path.startswith('/') and ':' in path:
             parts = path.split(':', 1)
             if parts[0]:


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list