Show More
@@ -237,3 +237,18 b' class bundlerepository(localrepo.localre' | |||
|
237 | 237 | self.bundlefile.close() |
|
238 | 238 | if self.tempfile is not None: |
|
239 | 239 | os.unlink(self.tempfile) |
|
240 | ||
|
241 | def instance(ui, path, create): | |
|
242 | if create: | |
|
243 | raise util.Abort(_('cannot create new bundle repository')) | |
|
244 | path = util.drop_scheme('file', path) | |
|
245 | if path.startswith('bundle:'): | |
|
246 | path = util.drop_scheme('bundle', path) | |
|
247 | s = path.split("+", 1) | |
|
248 | if len(s) == 1: | |
|
249 | repopath, bundlename = "", s[0] | |
|
250 | else: | |
|
251 | repopath, bundlename = s | |
|
252 | else: | |
|
253 | repopath, bundlename = '', path | |
|
254 | return bundlerepository(ui, repopath, bundlename) |
@@ -12,86 +12,43 b' from i18n import gettext as _' | |||
|
12 | 12 | demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo") |
|
13 | 13 | demandload(globals(), "errno lock os shutil util") |
|
14 | 14 | |
|
15 |
def |
|
|
16 | if path.startswith('bundle://'): | |
|
17 | path = path[9:] | |
|
18 | else: | |
|
19 | path = path[7:] | |
|
20 | s = path.split("+", 1) | |
|
21 | if len(s) == 1: | |
|
22 | repopath, bundlename = "", s[0] | |
|
23 | else: | |
|
24 | repopath, bundlename = s | |
|
25 | return bundlerepo.bundlerepository(ui, repopath, bundlename) | |
|
26 | ||
|
27 | def hg(ui, path): | |
|
28 | ui.warn(_("hg:// syntax is deprecated, please use http:// instead\n")) | |
|
29 | return httprepo.httprepository(ui, path.replace("hg://", "http://")) | |
|
30 | ||
|
31 | def local_(ui, path, create=0): | |
|
32 | if path.startswith('file:'): | |
|
33 | path = path[5:] | |
|
34 | if not create and os.path.isfile(path): | |
|
35 | return bundlerepo.bundlerepository(ui, '', path) | |
|
36 | return localrepo.localrepository(ui, path, create) | |
|
37 | ||
|
38 | def ssh_(ui, path, create=0): | |
|
39 | return sshrepo.sshrepository(ui, path, create) | |
|
40 | ||
|
41 | def old_http(ui, path): | |
|
42 | ui.warn(_("old-http:// syntax is deprecated, " | |
|
43 | "please use static-http:// instead\n")) | |
|
44 | return statichttprepo.statichttprepository( | |
|
45 | ui, path.replace("old-http://", "http://")) | |
|
46 | ||
|
47 | def static_http(ui, path): | |
|
48 | return statichttprepo.statichttprepository( | |
|
49 | ui, path.replace("static-http://", "http://")) | |
|
15 | def _local(path): | |
|
16 | return os.path.isfile(util.drop_scheme('file', path)) and bundlerepo or localrepo | |
|
50 | 17 | |
|
51 | 18 | schemes = { |
|
52 | 'bundle': bundle, | |
|
53 |
'file': local |
|
|
54 |
'hg': h |
|
|
55 | 'http': lambda ui, path: httprepo.httprepository(ui, path), | |
|
56 | 'https': lambda ui, path: httprepo.httpsrepository(ui, path), | |
|
57 |
'old-http': |
|
|
58 |
'ssh': ssh |
|
|
59 |
'static-http': static |
|
|
19 | 'bundle': bundlerepo, | |
|
20 | 'file': _local, | |
|
21 | 'hg': httprepo, | |
|
22 | 'http': httprepo, | |
|
23 | 'https': httprepo, | |
|
24 | 'old-http': statichttprepo, | |
|
25 | 'ssh': sshrepo, | |
|
26 | 'static-http': statichttprepo, | |
|
60 | 27 | } |
|
61 | 28 | |
|
62 | remote_schemes = [ | |
|
63 | 'bundle', | |
|
64 | 'hg', | |
|
65 | 'http', | |
|
66 | 'https', | |
|
67 | 'old-http', | |
|
68 | 'ssh', | |
|
69 | 'static-http', | |
|
70 | ] | |
|
71 | ||
|
29 | def _lookup(path): | |
|
30 | scheme = 'file' | |
|
31 | if path: | |
|
32 | c = path.find(':') | |
|
33 | if c > 0: | |
|
34 | scheme = path[:c] | |
|
35 | thing = schemes.get(scheme) or schemes['file'] | |
|
36 | try: | |
|
37 | return thing(path) | |
|
38 | except TypeError: | |
|
39 | return thing | |
|
40 | ||
|
72 | 41 | def islocal(repo): |
|
73 | 42 | '''return true if repo or path is local''' |
|
74 | 43 | if isinstance(repo, str): |
|
75 | c = repo.find(':') | |
|
76 | return c <= 0 or repo[:c] not in remote_schemes | |
|
44 | try: | |
|
45 | return _lookup(repo).islocal(repo) | |
|
46 | except AttributeError: | |
|
47 | return False | |
|
77 | 48 | return repo.local() |
|
78 | 49 | |
|
79 |
def repository(ui, path=None, create= |
|
|
80 | scheme = None | |
|
81 | if path: | |
|
82 | c = path.find(':') | |
|
83 | if c > 0: | |
|
84 | scheme = schemes.get(path[:c]) | |
|
85 | else: | |
|
86 | path = '' | |
|
87 | ctor = scheme or schemes['file'] | |
|
88 | if create: | |
|
89 | try: | |
|
90 | return ctor(ui, path, create) | |
|
91 | except TypeError: | |
|
92 | raise util.Abort(_('cannot create new repository over "%s" protocol') % | |
|
93 | scheme) | |
|
94 | return ctor(ui, path) | |
|
50 | def repository(ui, path=None, create=False): | |
|
51 | return _lookup(path).instance(ui, path, create) | |
|
95 | 52 | |
|
96 | 53 | def defaultdest(source): |
|
97 | 54 | '''return default destination of clone if none is given''' |
@@ -339,3 +339,13 b' class httpsrepository(httprepository):' | |||
|
339 | 339 | raise util.Abort(_('Python support for SSL and HTTPS ' |
|
340 | 340 | 'is not installed')) |
|
341 | 341 | httprepository.__init__(self, ui, path) |
|
342 | ||
|
343 | def instance(ui, path, create): | |
|
344 | if create: | |
|
345 | raise util.Abort(_('cannot create new http repository')) | |
|
346 | if path.startswith('hg:'): | |
|
347 | ui.warn(_("hg:// syntax is deprecated, please use http:// instead\n")) | |
|
348 | path = 'http:' + path[3:] | |
|
349 | if path.startswith('https:'): | |
|
350 | return httpsrepository(ui, path) | |
|
351 | return httprepository(ui, path) |
@@ -2271,3 +2271,8 b' def aftertrans(base):' | |||
|
2271 | 2271 | os.path.join(p, "undo.dirstate")) |
|
2272 | 2272 | return a |
|
2273 | 2273 | |
|
2274 | def instance(ui, path, create): | |
|
2275 | return localrepository(ui, util.drop_scheme('file', path), create) | |
|
2276 | ||
|
2277 | def islocal(path): | |
|
2278 | return True |
@@ -204,3 +204,5 b' class sshrepository(remoterepository):' | |||
|
204 | 204 | |
|
205 | 205 | def stream_out(self): |
|
206 | 206 | return self.do_cmd('stream_out') |
|
207 | ||
|
208 | instance = sshrepository |
@@ -7,9 +7,10 b'' | |||
|
7 | 7 | # This software may be used and distributed according to the terms |
|
8 | 8 | # of the GNU General Public License, incorporated herein by reference. |
|
9 | 9 | |
|
10 |
from demandload import |
|
|
10 | from demandload import * | |
|
11 | from i18n import gettext as _ | |
|
11 | 12 | demandload(globals(), "changelog filelog httprangereader") |
|
12 | demandload(globals(), "localrepo manifest os urllib urllib2") | |
|
13 | demandload(globals(), "localrepo manifest os urllib urllib2 util") | |
|
13 | 14 | |
|
14 | 15 | class rangereader(httprangereader.httprangereader): |
|
15 | 16 | def read(self, size=None): |
@@ -50,3 +51,14 b' class statichttprepository(localrepo.loc' | |||
|
50 | 51 | |
|
51 | 52 | def local(self): |
|
52 | 53 | return False |
|
54 | ||
|
55 | def instance(ui, path, create): | |
|
56 | if create: | |
|
57 | raise util.Abort(_('cannot create new static-http repository')) | |
|
58 | if path.startswith('old-http:'): | |
|
59 | ui.warn(_("old-http:// syntax is deprecated, " | |
|
60 | "please use static-http:// instead\n")) | |
|
61 | path = path[4:] | |
|
62 | else: | |
|
63 | path = path[7:] | |
|
64 | return statichttprepository(ui, path) |
@@ -996,3 +996,11 b' def bytecount(nbytes):' | |||
|
996 | 996 | if nbytes >= divisor * multiplier: |
|
997 | 997 | return format % (nbytes / float(divisor)) |
|
998 | 998 | return units[-1][2] % nbytes |
|
999 | ||
|
1000 | def drop_scheme(scheme, path): | |
|
1001 | sc = scheme + ':' | |
|
1002 | if path.startswith(sc): | |
|
1003 | path = path[len(sc):] | |
|
1004 | if path.startswith('//'): | |
|
1005 | path = path[2:] | |
|
1006 | return path |
General Comments 0
You need to be logged in to leave comments.
Login now