comparison mercurial/hg.py @ 1090:1bca39b85615

Move opener to utils - move the opener code down to util - add docstring - change commands.py users to simply use file instead
author mpm@selenic.com
date Sat, 27 Aug 2005 14:31:41 -0700
parents 142b5d5ec9cc
children 1f1661c58283
comparison
equal deleted inserted replaced
1089:142b5d5ec9cc 1090:1bca39b85615
11 from revlog import * 11 from revlog import *
12 from repo import * 12 from repo import *
13 from demandload import * 13 from demandload import *
14 demandload(globals(), "localrepo httprepo sshrepo") 14 demandload(globals(), "localrepo httprepo sshrepo")
15 15
16 # used to avoid circular references so destructors work
17 def opener(base):
18 p = base
19 def o(path, mode="r"):
20 if p.startswith("http://"):
21 f = os.path.join(p, urllib.quote(path))
22 return httprangereader.httprangereader(f)
23
24 f = os.path.join(p, path)
25
26 mode += "b" # for that other OS
27
28 if mode[0] != "r":
29 try:
30 s = os.stat(f)
31 except OSError:
32 d = os.path.dirname(f)
33 if not os.path.isdir(d):
34 os.makedirs(d)
35 else:
36 if s.st_nlink > 1:
37 file(f + ".tmp", "wb").write(file(f, "rb").read())
38 util.rename(f+".tmp", f)
39
40 return file(f, mode)
41
42 return o
43
44 def repository(ui, path=None, create=0): 16 def repository(ui, path=None, create=0):
45 if path: 17 if path:
46 if path.startswith("http://"): 18 if path.startswith("http://"):
47 return httprepo.httprepository(ui, path) 19 return httprepo.httprepository(ui, path)
48 if path.startswith("https://"): 20 if path.startswith("https://"):
50 if path.startswith("hg://"): 22 if path.startswith("hg://"):
51 return httprepo.httprepository( 23 return httprepo.httprepository(
52 ui, path.replace("hg://", "http://")) 24 ui, path.replace("hg://", "http://"))
53 if path.startswith("old-http://"): 25 if path.startswith("old-http://"):
54 return localrepo.localrepository( 26 return localrepo.localrepository(
55 ui, opener, path.replace("old-http://", "http://")) 27 ui, util.opener, path.replace("old-http://", "http://"))
56 if path.startswith("ssh://"): 28 if path.startswith("ssh://"):
57 return sshrepo.sshrepository(ui, path) 29 return sshrepo.sshrepository(ui, path)
58 30
59 return localrepo.localrepository(ui, opener, path, create) 31 return localrepo.localrepository(ui, util.opener, path, create)