##// END OF EJS Templates
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer -
r2740:386f04d6 default
parent child Browse files
Show More
@@ -237,3 +237,18 b' class bundlerepository(localrepo.localre'
237 self.bundlefile.close()
237 self.bundlefile.close()
238 if self.tempfile is not None:
238 if self.tempfile is not None:
239 os.unlink(self.tempfile)
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 demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo")
12 demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo")
13 demandload(globals(), "errno lock os shutil util")
13 demandload(globals(), "errno lock os shutil util")
14
14
15 def bundle(ui, path):
15 def _local(path):
16 if path.startswith('bundle://'):
16 return os.path.isfile(util.drop_scheme('file', path)) and bundlerepo or localrepo
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://"))
50
17
51 schemes = {
18 schemes = {
52 'bundle': bundle,
19 'bundle': bundlerepo,
53 'file': local_,
20 'file': _local,
54 'hg': hg,
21 'hg': httprepo,
55 'http': lambda ui, path: httprepo.httprepository(ui, path),
22 'http': httprepo,
56 'https': lambda ui, path: httprepo.httpsrepository(ui, path),
23 'https': httprepo,
57 'old-http': old_http,
24 'old-http': statichttprepo,
58 'ssh': ssh_,
25 'ssh': sshrepo,
59 'static-http': static_http,
26 'static-http': statichttprepo,
60 }
27 }
61
28
62 remote_schemes = [
29 def _lookup(path):
63 'bundle',
30 scheme = 'file'
64 'hg',
31 if path:
65 'http',
32 c = path.find(':')
66 'https',
33 if c > 0:
67 'old-http',
34 scheme = path[:c]
68 'ssh',
35 thing = schemes.get(scheme) or schemes['file']
69 'static-http',
36 try:
70 ]
37 return thing(path)
71
38 except TypeError:
39 return thing
40
72 def islocal(repo):
41 def islocal(repo):
73 '''return true if repo or path is local'''
42 '''return true if repo or path is local'''
74 if isinstance(repo, str):
43 if isinstance(repo, str):
75 c = repo.find(':')
44 try:
76 return c <= 0 or repo[:c] not in remote_schemes
45 return _lookup(repo).islocal(repo)
46 except AttributeError:
47 return False
77 return repo.local()
48 return repo.local()
78
49
79 def repository(ui, path=None, create=0):
50 def repository(ui, path=None, create=False):
80 scheme = None
51 return _lookup(path).instance(ui, path, create)
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)
95
52
96 def defaultdest(source):
53 def defaultdest(source):
97 '''return default destination of clone if none is given'''
54 '''return default destination of clone if none is given'''
@@ -339,3 +339,13 b' class httpsrepository(httprepository):'
339 raise util.Abort(_('Python support for SSL and HTTPS '
339 raise util.Abort(_('Python support for SSL and HTTPS '
340 'is not installed'))
340 'is not installed'))
341 httprepository.__init__(self, ui, path)
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 os.path.join(p, "undo.dirstate"))
2271 os.path.join(p, "undo.dirstate"))
2272 return a
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 def stream_out(self):
205 def stream_out(self):
206 return self.do_cmd('stream_out')
206 return self.do_cmd('stream_out')
207
208 instance = sshrepository
@@ -7,9 +7,10 b''
7 # This software may be used and distributed according to the terms
7 # This software may be used and distributed according to the terms
8 # of the GNU General Public License, incorporated herein by reference.
8 # of the GNU General Public License, incorporated herein by reference.
9
9
10 from demandload import demandload
10 from demandload import *
11 from i18n import gettext as _
11 demandload(globals(), "changelog filelog httprangereader")
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 class rangereader(httprangereader.httprangereader):
15 class rangereader(httprangereader.httprangereader):
15 def read(self, size=None):
16 def read(self, size=None):
@@ -50,3 +51,14 b' class statichttprepository(localrepo.loc'
50
51
51 def local(self):
52 def local(self):
52 return False
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 if nbytes >= divisor * multiplier:
996 if nbytes >= divisor * multiplier:
997 return format % (nbytes / float(divisor))
997 return format % (nbytes / float(divisor))
998 return units[-1][2] % nbytes
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