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