Show More
@@ -15,7 +15,7 from node import nullid | |||
|
15 | 15 | from i18n import _ |
|
16 | 16 | import os, struct, tempfile, shutil |
|
17 | 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 | 20 | class bundlerevlog(revlog.revlog): |
|
21 | 21 | def __init__(self, opener, indexfile, bundle, |
@@ -274,9 +274,9 def instance(ui, path, create): | |||
|
274 | 274 | cwd = os.path.join(cwd,'') |
|
275 | 275 | if parentpath.startswith(cwd): |
|
276 | 276 | parentpath = parentpath[len(cwd):] |
|
277 | path = util.drop_scheme('file', path) | |
|
278 | if path.startswith('bundle:'): | |
|
279 | path = util.drop_scheme('bundle', path) | |
|
277 | u = url.url(path) | |
|
278 | path = u.localpath() | |
|
279 | if u.scheme == 'bundle': | |
|
280 | 280 | s = path.split("+", 1) |
|
281 | 281 | if len(s) == 1: |
|
282 | 282 | repopath, bundlename = parentpath, s[0] |
@@ -17,7 +17,7 import verify as verifymod | |||
|
17 | 17 | import errno, os, shutil |
|
18 | 18 | |
|
19 | 19 | def _local(path): |
|
20 |
path = util.expandpath(u |
|
|
20 | path = util.expandpath(url.localpath(path)) | |
|
21 | 21 | return (os.path.isfile(path) and bundlerepo or localrepo) |
|
22 | 22 | |
|
23 | 23 | def addbranchrevs(lrepo, repo, branches, revs): |
@@ -102,15 +102,6 def defaultdest(source): | |||
|
102 | 102 | '''return default destination of clone if none is given''' |
|
103 | 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 | 105 | def share(ui, source, dest=None, update=True): |
|
115 | 106 | '''create a shared repository''' |
|
116 | 107 | |
@@ -230,8 +221,8 def clone(ui, source, dest=None, pull=Fa | |||
|
230 | 221 | else: |
|
231 | 222 | dest = ui.expandpath(dest) |
|
232 | 223 | |
|
233 | dest = localpath(dest) | |
|
234 | source = localpath(source) | |
|
224 | dest = url.localpath(dest) | |
|
225 | source = url.localpath(source) | |
|
235 | 226 | |
|
236 | 227 | if os.path.exists(dest): |
|
237 | 228 | if not os.path.isdir(dest): |
@@ -257,7 +248,7 def clone(ui, source, dest=None, pull=Fa | |||
|
257 | 248 | abspath = origsource |
|
258 | 249 | copy = False |
|
259 | 250 | if src_repo.cancopy() and islocal(dest): |
|
260 |
abspath = os.path.abspath(u |
|
|
251 | abspath = os.path.abspath(url.localpath(origsource)) | |
|
261 | 252 | copy = not pull and not rev |
|
262 | 253 | |
|
263 | 254 | if copy: |
@@ -1928,7 +1928,7 def aftertrans(files): | |||
|
1928 | 1928 | return a |
|
1929 | 1929 | |
|
1930 | 1930 | def instance(ui, path, create): |
|
1931 |
return localrepository(ui, u |
|
|
1931 | return localrepository(ui, urlmod.localpath(path), create) | |
|
1932 | 1932 | |
|
1933 | 1933 | def islocal(path): |
|
1934 | 1934 | return True |
@@ -70,6 +70,8 class url(object): | |||
|
70 | 70 | self.scheme = self.user = self.passwd = self.host = None |
|
71 | 71 | self.port = self.path = self.query = self.fragment = None |
|
72 | 72 | self._localpath = True |
|
73 | self._hostport = '' | |
|
74 | self._origpath = path | |
|
73 | 75 | |
|
74 | 76 | # special case for Windows drive letters |
|
75 | 77 | if has_drive_letter(path): |
@@ -137,6 +139,7 class url(object): | |||
|
137 | 139 | # Don't split on colons in IPv6 addresses without ports |
|
138 | 140 | if (self.host and ':' in self.host and |
|
139 | 141 | not (self.host.startswith('[') and self.host.endswith(']'))): |
|
142 | self._hostport = self.host | |
|
140 | 143 | self.host, self.port = self.host.rsplit(':', 1) |
|
141 | 144 | if not self.host: |
|
142 | 145 | self.host = None |
@@ -231,12 +234,32 class url(object): | |||
|
231 | 234 | return (s, (None, (str(self), self.host), |
|
232 | 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 | 254 | def has_scheme(path): |
|
235 | 255 | return bool(url(path).scheme) |
|
236 | 256 | |
|
237 | 257 | def has_drive_letter(path): |
|
238 | 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 | 263 | def hidepassword(u): |
|
241 | 264 | '''hide user credential in a url string''' |
|
242 | 265 | u = url(u) |
@@ -1384,26 +1384,6 def bytecount(nbytes): | |||
|
1384 | 1384 | return format % (nbytes / float(divisor)) |
|
1385 | 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 | 1387 | def uirepr(s): |
|
1408 | 1388 | # Avoid double backslash in Windows path repr() |
|
1409 | 1389 | return repr(s).replace('\\\\', '\\') |
@@ -470,6 +470,22 test for 540d1059c802 | |||
|
470 | 470 | |
|
471 | 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 | 489 | test for http://mercurial.selenic.com/bts/issue1144 |
|
474 | 490 | |
|
475 | 491 | test that verify bundle does not traceback |
@@ -71,6 +71,10 Test 'file:' uri handling: | |||
|
71 | 71 | abort: file:// URLs can only refer to localhost |
|
72 | 72 | [255] |
|
73 | 73 | |
|
74 | $ hg pull -q file://../test | |
|
75 | abort: file:// URLs can only refer to localhost | |
|
76 | [255] | |
|
77 | ||
|
74 | 78 | $ hg pull -q file:../test |
|
75 | 79 | |
|
76 | 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