diff 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
line wrap: on
line diff
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -13,34 +13,6 @@ from repo import *
 from demandload import *
 demandload(globals(), "localrepo httprepo sshrepo")
 
-# used to avoid circular references so destructors work
-def opener(base):
-    p = base
-    def o(path, mode="r"):
-        if p.startswith("http://"):
-            f = os.path.join(p, urllib.quote(path))
-            return httprangereader.httprangereader(f)
-
-        f = os.path.join(p, path)
-
-        mode += "b" # for that other OS
-
-        if mode[0] != "r":
-            try:
-                s = os.stat(f)
-            except OSError:
-                d = os.path.dirname(f)
-                if not os.path.isdir(d):
-                    os.makedirs(d)
-            else:
-                if s.st_nlink > 1:
-                    file(f + ".tmp", "wb").write(file(f, "rb").read())
-                    util.rename(f+".tmp", f)
-
-        return file(f, mode)
-
-    return o
-
 def repository(ui, path=None, create=0):
     if path:
         if path.startswith("http://"):
@@ -52,8 +24,8 @@ def repository(ui, path=None, create=0):
                 ui, path.replace("hg://", "http://"))
         if path.startswith("old-http://"):
             return localrepo.localrepository(
-                ui, opener, path.replace("old-http://", "http://"))
+                ui, util.opener, path.replace("old-http://", "http://"))
         if path.startswith("ssh://"):
             return sshrepo.sshrepository(ui, path)
 
-    return localrepo.localrepository(ui, opener, path, create)
+    return localrepo.localrepository(ui, util.opener, path, create)