comparison mercurial/util.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 43b5fe18ea6c
children 28f557e8b419
comparison
equal deleted inserted replaced
13825:cc383142e738 13826:e574207e3bcd
1382 for multiplier, divisor, format in units: 1382 for multiplier, divisor, format in units:
1383 if nbytes >= divisor * multiplier: 1383 if nbytes >= divisor * multiplier:
1384 return format % (nbytes / float(divisor)) 1384 return format % (nbytes / float(divisor))
1385 return units[-1][2] % nbytes 1385 return units[-1][2] % nbytes
1386 1386
1387 def drop_scheme(scheme, path):
1388 sc = scheme + ':'
1389 if path.startswith(sc):
1390 path = path[len(sc):]
1391 if path.startswith('//'):
1392 if scheme == 'file':
1393 i = path.find('/', 2)
1394 if i == -1:
1395 return ''
1396 # On Windows, absolute paths are rooted at the current drive
1397 # root. On POSIX they are rooted at the file system root.
1398 if os.name == 'nt':
1399 droot = os.path.splitdrive(os.getcwd())[0] + '/'
1400 path = os.path.join(droot, path[i + 1:])
1401 else:
1402 path = path[i:]
1403 else:
1404 path = path[2:]
1405 return path
1406
1407 def uirepr(s): 1387 def uirepr(s):
1408 # Avoid double backslash in Windows path repr() 1388 # Avoid double backslash in Windows path repr()
1409 return repr(s).replace('\\\\', '\\') 1389 return repr(s).replace('\\\\', '\\')
1410 1390
1411 # delay import of textwrap 1391 # delay import of textwrap