##// END OF EJS Templates
hg.repository: make protocol table driven....
Vadim Gelfer -
r2469:2e91ba37 default
parent child Browse files
Show More
@@ -11,34 +11,60 b' from demandload import *'
11 from i18n import gettext as _
11 from i18n import gettext as _
12 demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo")
12 demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo")
13
13
14 def bundle(ui, path):
15 if path.startswith('bundle://'):
16 path = path[9:]
17 else:
18 path = path[7:]
19 s = path.split("+", 1)
20 if len(s) == 1:
21 repopath, bundlename = "", s[0]
22 else:
23 repopath, bundlename = s
24 return bundlerepo.bundlerepository(ui, repopath, bundlename)
25
26 def hg(ui, path):
27 ui.warn(_("hg:// syntax is deprecated, please use http:// instead\n"))
28 return httprepo.httprepository(ui, path.replace("hg://", "http://"))
29
30 def local_(ui, path, create=0):
31 return localrepo.localrepository(ui, path, create)
32
33 def old_http(ui, path):
34 ui.warn(_("old-http:// syntax is deprecated, "
35 "please use static-http:// instead\n"))
36 return statichttprepo.statichttprepository(
37 ui, path.replace("old-http://", "http://"))
38
39 def static_http(ui, path):
40 return statichttprepo.statichttprepository(
41 ui, path.replace("static-http://", "http://"))
42
43 protocols = {
44 'bundle': bundle,
45 'file': local_,
46 'hg': hg,
47 'http': lambda ui, path: httprepo.httprepository(ui, path),
48 'https': lambda ui, path: httprepo.httpsrepository(ui, path),
49 'old-http': old_http,
50 'ssh': lambda ui, path: sshrepo.sshrepository(ui, path),
51 'static-http': static_http,
52 None: local_,
53 }
54
14 def repository(ui, path=None, create=0):
55 def repository(ui, path=None, create=0):
15 if path:
56 scheme = path
16 if path.startswith("http://"):
57 if scheme:
17 return httprepo.httprepository(ui, path)
58 c = scheme.find(':')
18 if path.startswith("https://"):
59 scheme = c >= 0 and scheme[:c]
19 return httprepo.httpsrepository(ui, path)
60 if not scheme: scheme = None
20 if path.startswith("hg://"):
61 try:
21 ui.warn(_("hg:// syntax is deprecated, "
62 ctor = protocols[scheme]
22 "please use http:// instead\n"))
63 if create:
23 return httprepo.httprepository(
64 return ctor(ui, path, create)
24 ui, path.replace("hg://", "http://"))
65 return ctor(ui, path)
25 if path.startswith("old-http://"):
66 except KeyError:
26 ui.warn(_("old-http:// syntax is deprecated, "
67 raise util.Abort(_('protocol "%s" not known') % scheme)
27 "please use static-http:// instead\n"))
68 except TypeError:
28 return statichttprepo.statichttprepository(
69 raise util.Abort(_('cannot create new repository over "%s" protocol') %
29 ui, path.replace("old-http://", "http://"))
70 (scheme or 'file'))
30 if path.startswith("static-http://"):
31 return statichttprepo.statichttprepository(
32 ui, path.replace("static-http://", "http://"))
33 if path.startswith("ssh://"):
34 return sshrepo.sshrepository(ui, path)
35 if path.startswith("bundle://"):
36 path = path[9:]
37 s = path.split("+", 1)
38 if len(s) == 1:
39 repopath, bundlename = "", s[0]
40 else:
41 repopath, bundlename = s
42 return bundlerepo.bundlerepository(ui, repopath, bundlename)
43
44 return localrepo.localrepository(ui, path, create)
General Comments 0
You need to be logged in to leave comments. Login now