Mercurial > public > mercurial-scm > hg
comparison mercurial/bundlerepo.py @ 13826:e574207e3bcd
url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
This replaces util.drop_scheme() with url.localpath(), using url.url for
parsing instead of doing it on its own. The function is moved from
util to url to avoid an import cycle.
hg.localpath() is removed in favor of using url.localpath(). This
provides more consistent behavior between "hg clone" and other
commands.
To preserve backwards compatibility, URLs like bundle://../foo still
refer to ../foo, not /foo.
If a URL contains a scheme, percent-encoded entities are decoded. When
there's no scheme, all characters are left untouched.
Comparison of old and new behaviors:
URL drop_scheme() hg.localpath() url.localpath()
=== ============= ============== ===============
file://foo/foo /foo foo/foo /foo
file://localhost:80/foo /foo localhost:80/foo /foo
file://localhost:/foo /foo localhost:/foo /foo
file://localhost/foo /foo /foo /foo
file:///foo /foo /foo /foo
file://foo (empty string) foo /
file:/foo /foo /foo /foo
file:foo foo foo foo
file:foo%23bar foo%23bar foo%23bar foo#bar
foo%23bar foo%23bar foo%23bar foo%23bar
/foo /foo /foo /foo
Windows-related paths on Windows:
URL drop_scheme() hg.localpath() url.localpath()
=== ============= ============== ===============
file:///C:/foo C:/C:/foo /C:/foo C:/foo
file:///D:/foo C:/D:/foo /D:/foo D:/foo
file://C:/foo C:/foo C:/foo C:/foo
file://D:/foo C:/foo D:/foo D:/foo
file:////foo/bar //foo/bar //foo/bar //foo/bar
//foo/bar //foo/bar //foo/bar //foo/bar
\\foo\bar //foo/bar //foo/bar \\foo\bar
Windows-related paths on other platforms:
file:///C:/foo C:/C:/foo /C:/foo C:/foo
file:///D:/foo C:/D:/foo /D:/foo D:/foo
file://C:/foo C:/foo C:/foo C:/foo
file://D:/foo C:/foo D:/foo D:/foo
file:////foo/bar //foo/bar //foo/bar //foo/bar
//foo/bar //foo/bar //foo/bar //foo/bar
\\foo\bar //foo/bar //foo/bar \\foo\bar
For more information about file:// URL handling, see:
http://www-archive.mozilla.org/quality/networking/testing/filetests.html
Related issues:
- issue1153: File URIs aren't handled correctly in windows
This patch should preserve the fix implemented in
2770d03ae49f. However, it goes a step further and "promotes"
Windows-style drive letters from being interpreted as host names to
being part of the path.
- issue2154: Cannot escape '#' in Mercurial URLs (#1172 in THG)
The fragment is still interpreted as a revision or a branch, even in
paths to bundles. However, when file: is used, percent-encoded
entities are decoded, so file:test%23bundle.hg can refer to
test#bundle.hg ond isk.
author | Brodie Rao <brodie@bitheap.org> |
---|---|
date | Wed, 30 Mar 2011 20:03:05 -0700 |
parents | 7abab875e647 |
children | 97ed99d1f419 |
comparison
equal
deleted
inserted
replaced
13825:cc383142e738 | 13826:e574207e3bcd |
---|---|
13 | 13 |
14 from node import nullid | 14 from node import nullid |
15 from i18n import _ | 15 from i18n import _ |
16 import os, struct, tempfile, shutil | 16 import os, struct, tempfile, shutil |
17 import changegroup, util, mdiff, discovery | 17 import changegroup, util, mdiff, discovery |
18 import localrepo, changelog, manifest, filelog, revlog, error | 18 import localrepo, changelog, manifest, filelog, revlog, error, url |
19 | 19 |
20 class bundlerevlog(revlog.revlog): | 20 class bundlerevlog(revlog.revlog): |
21 def __init__(self, opener, indexfile, bundle, | 21 def __init__(self, opener, indexfile, bundle, |
22 linkmapper=None): | 22 linkmapper=None): |
23 # How it works: | 23 # How it works: |
272 parentpath = '' | 272 parentpath = '' |
273 else: | 273 else: |
274 cwd = os.path.join(cwd,'') | 274 cwd = os.path.join(cwd,'') |
275 if parentpath.startswith(cwd): | 275 if parentpath.startswith(cwd): |
276 parentpath = parentpath[len(cwd):] | 276 parentpath = parentpath[len(cwd):] |
277 path = util.drop_scheme('file', path) | 277 u = url.url(path) |
278 if path.startswith('bundle:'): | 278 path = u.localpath() |
279 path = util.drop_scheme('bundle', path) | 279 if u.scheme == 'bundle': |
280 s = path.split("+", 1) | 280 s = path.split("+", 1) |
281 if len(s) == 1: | 281 if len(s) == 1: |
282 repopath, bundlename = parentpath, s[0] | 282 repopath, bundlename = parentpath, s[0] |
283 else: | 283 else: |
284 repopath, bundlename = s | 284 repopath, bundlename = s |