##// END OF EJS Templates
Move opener to utils...
mpm@selenic.com -
r1090:1bca39b8 default
parent child Browse files
Show More
@@ -690,12 +690,12 def debugstate(ui, repo):
690 690
691 691 def debugdata(ui, file_, rev):
692 692 """dump the contents of an data file revision"""
693 r = hg.revlog(hg.opener(""), file_[:-2] + ".i", file_)
693 r = hg.revlog(file, file_[:-2] + ".i", file_)
694 694 ui.write(r.revision(r.lookup(rev)))
695 695
696 696 def debugindex(ui, file_):
697 697 """dump the contents of an index file"""
698 r = hg.revlog(hg.opener(""), file_, "")
698 r = hg.revlog(file, file_, "")
699 699 ui.write(" rev offset length base linkrev" +
700 700 " nodeid p1 p2\n")
701 701 for i in range(r.count()):
@@ -706,7 +706,7 def debugindex(ui, file_):
706 706
707 707 def debugindexdot(ui, file_):
708 708 """dump an index DAG as a .dot file"""
709 r = hg.revlog(hg.opener(""), file_, "")
709 r = hg.revlog(file, file_, "")
710 710 ui.write("digraph G {\n")
711 711 for i in range(r.count()):
712 712 e = r.index[i]
@@ -13,34 +13,6 from repo import *
13 13 from demandload import *
14 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 16 def repository(ui, path=None, create=0):
45 17 if path:
46 18 if path.startswith("http://"):
@@ -52,8 +24,8 def repository(ui, path=None, create=0):
52 24 ui, path.replace("hg://", "http://"))
53 25 if path.startswith("old-http://"):
54 26 return localrepo.localrepository(
55 ui, opener, path.replace("old-http://", "http://"))
27 ui, util.opener, path.replace("old-http://", "http://"))
56 28 if path.startswith("ssh://"):
57 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)
@@ -232,6 +232,41 def copytree(src, dst, copyfile):
232 232 else:
233 233 pass
234 234
235 def opener(base):
236 """
237 return a function that opens files relative to base
238
239 this function is used to hide the details of COW semantics and
240 remote file access from higher level code.
241
242 todo: separate remote file access into a separate function
243 """
244 p = base
245 def o(path, mode="r"):
246 if p.startswith("http://"):
247 f = os.path.join(p, urllib.quote(path))
248 return httprangereader.httprangereader(f)
249
250 f = os.path.join(p, path)
251
252 mode += "b" # for that other OS
253
254 if mode[0] != "r":
255 try:
256 s = os.stat(f)
257 except OSError:
258 d = os.path.dirname(f)
259 if not os.path.isdir(d):
260 os.makedirs(d)
261 else:
262 if s.st_nlink > 1:
263 file(f + ".tmp", "wb").write(file(f, "rb").read())
264 rename(f+".tmp", f)
265
266 return file(f, mode)
267
268 return o
269
235 270 def _makelock_file(info, pathname):
236 271 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL)
237 272 os.write(ld, info)
General Comments 0
You need to be logged in to leave comments. Login now