[PATCH 03 of 13 RFC] url: special case bundle URL parsing to preserve backwards compatibility
Brodie Rao
brodie at bitheap.org
Wed Mar 30 22:11:48 CDT 2011
# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1301540424 25200
# Node ID e5b2b7cd3a419e0ea3a5b0b92814885e61fd8724
# Parent 0ba05012f167859a1bbd4ebc7bfe5e9012d895ef
url: special case bundle URL parsing to preserve backwards compatibility
This allows bundle://../foo to continue to refer to the relative path
../foo (bundle URLs do not take host names).
diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -29,6 +29,9 @@ class url(object):
See http://www.ietf.org/rfc/rfc2396.txt for more information.
+ Note that for backward compatibility reasons, bundle URLs do not
+ take host names. That means 'bundle://../' has a path of '../'.
+
Examples:
>>> url('http://www.ietf.org/rfc/rfc2396.txt')
@@ -39,6 +42,8 @@ class url(object):
<url scheme: 'file', path: '/home/joe/repo'>
>>> url('bundle:foo')
<url scheme: 'bundle', path: 'foo'>
+ >>> url('bundle://../foo')
+ <url scheme: 'bundle', path: '../foo'>
>>> url('c:\\\\foo\\\\bar')
<url path: 'c:\\\\foo\\\\bar'>
@@ -71,6 +76,16 @@ class url(object):
self.path = path
return
+ # For compatibility reasons, we can't handle bundle paths as
+ # normal URLS
+ if path.startswith('bundle:'):
+ self.scheme = 'bundle'
+ path = path[7:]
+ if path.startswith('//'):
+ path = path[2:]
+ self.path = path
+ return
+
if not path.startswith('/') and ':' in path:
parts = path.split(':', 1)
if parts[0]:
@@ -159,11 +174,15 @@ class url(object):
'http://localhost:80/'
>>> str(url('bundle:foo'))
'bundle:foo'
+ >>> str(url('bundle://../foo'))
+ 'bundle:../foo'
>>> str(url('path'))
'path'
"""
if self._localpath:
s = self.path
+ if self.scheme == 'bundle':
+ s = 'bundle:' + s
if self.fragment:
s += '#' + self.fragment
return s
More information about the Mercurial-devel
mailing list