##// END OF EJS Templates
make repo scheme table driven.
Vadim Gelfer -
r2472:e6ec81a8 default
parent child Browse files
Show More
@@ -10,35 +10,60 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")
14
15 def bundle(ui, path):
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 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 }
13
56
14 def repository(ui, path=None, create=0):
57 def repository(ui, path=None, create=0):
15 if path:
58 scheme = path
16 if path.startswith("http://"):
59 if scheme:
17 return httprepo.httprepository(ui, path)
60 c = scheme.find(':')
18 if path.startswith("https://"):
61 scheme = c >= 0 and scheme[:c]
19 return httprepo.httpsrepository(ui, path)
62 try:
20 if path.startswith("hg://"):
63 ctor = schemes.get(scheme) or schemes['file']
21 ui.warn(_("hg:// syntax is deprecated, "
64 if create:
22 "please use http:// instead\n"))
65 return ctor(ui, path, create)
23 return httprepo.httprepository(
66 return ctor(ui, path)
24 ui, path.replace("hg://", "http://"))
67 except TypeError:
25 if path.startswith("old-http://"):
68 raise util.Abort(_('cannot create new repository over "%s" protocol') %
26 ui.warn(_("old-http:// syntax is deprecated, "
69 scheme)
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:]
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