##// END OF EJS Templates
url: refactor util.drop_scheme() and hg.localpath() into url.localpath()...
Brodie Rao -
r13826:e574207e default
parent child Browse files
Show More
@@ -15,7 +15,7 b' 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,
@@ -274,9 +274,9 b' def instance(ui, path, create):'
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]
@@ -17,7 +17,7 b' import verify as verifymod'
17 import errno, os, shutil
17 import errno, os, shutil
18
18
19 def _local(path):
19 def _local(path):
20 path = util.expandpath(util.drop_scheme('file', path))
20 path = util.expandpath(url.localpath(path))
21 return (os.path.isfile(path) and bundlerepo or localrepo)
21 return (os.path.isfile(path) and bundlerepo or localrepo)
22
22
23 def addbranchrevs(lrepo, repo, branches, revs):
23 def addbranchrevs(lrepo, repo, branches, revs):
@@ -102,15 +102,6 b' def defaultdest(source):'
102 '''return default destination of clone if none is given'''
102 '''return default destination of clone if none is given'''
103 return os.path.basename(os.path.normpath(source))
103 return os.path.basename(os.path.normpath(source))
104
104
105 def localpath(path):
106 if path.startswith('file://localhost/'):
107 return path[16:]
108 if path.startswith('file://'):
109 return path[7:]
110 if path.startswith('file:'):
111 return path[5:]
112 return path
113
114 def share(ui, source, dest=None, update=True):
105 def share(ui, source, dest=None, update=True):
115 '''create a shared repository'''
106 '''create a shared repository'''
116
107
@@ -230,8 +221,8 b' def clone(ui, source, dest=None, pull=Fa'
230 else:
221 else:
231 dest = ui.expandpath(dest)
222 dest = ui.expandpath(dest)
232
223
233 dest = localpath(dest)
224 dest = url.localpath(dest)
234 source = localpath(source)
225 source = url.localpath(source)
235
226
236 if os.path.exists(dest):
227 if os.path.exists(dest):
237 if not os.path.isdir(dest):
228 if not os.path.isdir(dest):
@@ -257,7 +248,7 b' def clone(ui, source, dest=None, pull=Fa'
257 abspath = origsource
248 abspath = origsource
258 copy = False
249 copy = False
259 if src_repo.cancopy() and islocal(dest):
250 if src_repo.cancopy() and islocal(dest):
260 abspath = os.path.abspath(util.drop_scheme('file', origsource))
251 abspath = os.path.abspath(url.localpath(origsource))
261 copy = not pull and not rev
252 copy = not pull and not rev
262
253
263 if copy:
254 if copy:
@@ -1928,7 +1928,7 b' def aftertrans(files):'
1928 return a
1928 return a
1929
1929
1930 def instance(ui, path, create):
1930 def instance(ui, path, create):
1931 return localrepository(ui, util.drop_scheme('file', path), create)
1931 return localrepository(ui, urlmod.localpath(path), create)
1932
1932
1933 def islocal(path):
1933 def islocal(path):
1934 return True
1934 return True
@@ -70,6 +70,8 b' class url(object):'
70 self.scheme = self.user = self.passwd = self.host = None
70 self.scheme = self.user = self.passwd = self.host = None
71 self.port = self.path = self.query = self.fragment = None
71 self.port = self.path = self.query = self.fragment = None
72 self._localpath = True
72 self._localpath = True
73 self._hostport = ''
74 self._origpath = path
73
75
74 # special case for Windows drive letters
76 # special case for Windows drive letters
75 if has_drive_letter(path):
77 if has_drive_letter(path):
@@ -137,6 +139,7 b' class url(object):'
137 # Don't split on colons in IPv6 addresses without ports
139 # Don't split on colons in IPv6 addresses without ports
138 if (self.host and ':' in self.host and
140 if (self.host and ':' in self.host and
139 not (self.host.startswith('[') and self.host.endswith(']'))):
141 not (self.host.startswith('[') and self.host.endswith(']'))):
142 self._hostport = self.host
140 self.host, self.port = self.host.rsplit(':', 1)
143 self.host, self.port = self.host.rsplit(':', 1)
141 if not self.host:
144 if not self.host:
142 self.host = None
145 self.host = None
@@ -231,12 +234,32 b' class url(object):'
231 return (s, (None, (str(self), self.host),
234 return (s, (None, (str(self), self.host),
232 self.user, self.passwd or ''))
235 self.user, self.passwd or ''))
233
236
237 def localpath(self):
238 if self.scheme == 'file' or self.scheme == 'bundle':
239 path = self.path or '/'
240 # For Windows, we need to promote hosts containing drive
241 # letters to paths with drive letters.
242 if has_drive_letter(self._hostport):
243 path = self._hostport + '/' + self.path
244 elif self.host is not None and self.path:
245 path = '/' + path
246 # We also need to handle the case of file:///C:/, which
247 # should return C:/, not /C:/.
248 elif has_drive_letter(path):
249 # Strip leading slash from paths with drive names
250 return path[1:]
251 return path
252 return self._origpath
253
234 def has_scheme(path):
254 def has_scheme(path):
235 return bool(url(path).scheme)
255 return bool(url(path).scheme)
236
256
237 def has_drive_letter(path):
257 def has_drive_letter(path):
238 return path[1:2] == ':' and path[0:1].isalpha()
258 return path[1:2] == ':' and path[0:1].isalpha()
239
259
260 def localpath(path):
261 return url(path, parse_query=False, parse_fragment=False).localpath()
262
240 def hidepassword(u):
263 def hidepassword(u):
241 '''hide user credential in a url string'''
264 '''hide user credential in a url string'''
242 u = url(u)
265 u = url(u)
@@ -1384,26 +1384,6 b' def bytecount(nbytes):'
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('\\\\', '\\')
@@ -470,6 +470,22 b' test for 540d1059c802'
470
470
471 $ cd ..
471 $ cd ..
472
472
473 test bundle with # in the filename (issue2154):
474
475 $ cp bundle.hg 'test#bundle.hg'
476 $ cd orig
477 $ hg incoming '../test#bundle.hg'
478 comparing with ../test
479 abort: unknown revision 'bundle.hg'!
480 [255]
481
482 note that percent encoding is not handled:
483
484 $ hg incoming ../test%23bundle.hg
485 abort: repository ../test%23bundle.hg not found!
486 [255]
487 $ cd ..
488
473 test for http://mercurial.selenic.com/bts/issue1144
489 test for http://mercurial.selenic.com/bts/issue1144
474
490
475 test that verify bundle does not traceback
491 test that verify bundle does not traceback
@@ -71,6 +71,10 b" Test 'file:' uri handling:"
71 abort: file:// URLs can only refer to localhost
71 abort: file:// URLs can only refer to localhost
72 [255]
72 [255]
73
73
74 $ hg pull -q file://../test
75 abort: file:// URLs can only refer to localhost
76 [255]
77
74 $ hg pull -q file:../test
78 $ hg pull -q file:../test
75
79
76 It's tricky to make file:// URLs working on every platform with
80 It's tricky to make file:// URLs working on every platform with
General Comments 0
You need to be logged in to leave comments. Login now