changeset 291:2c4f2be05587

Add wopener for opening files in the working directory -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Add wopener for opening files in the working directory manifest hash: cad3a930764244a32f8e45c2ea95fa9b98690b5f -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp5qxywK+sNU5EO8RAkfAAJ9C7V8zlbUVM8Dfs4raXMtT2bk4RQCfRfVt IfYoaVsbOUW4U1XipOZycAw= =5JDH -----END PGP SIGNATURE-----
author mpm@selenic.com
date Wed, 08 Jun 2005 17:26:09 -0800
parents 07c6cb9fd1c5
children 09364bcebdf0
files mercurial/hg.py
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Wed Jun 08 17:08:55 2005 -0800
+++ b/mercurial/hg.py	Wed Jun 08 17:26:09 2005 -0800
@@ -318,6 +318,7 @@
             os.mkdir(self.join("data"))
 
         self.opener = opener(self.path)
+        self.wopener = opener(self.root)
         self.manifest = manifest(self.opener)
         self.changelog = changelog(self.opener)
         self.ignorelist = None
@@ -330,7 +331,7 @@
         if self.ignorelist is None:
             self.ignorelist = []
             try:
-                l = open(os.path.join(self.root, ".hgignore"))
+                l = self.wfile(".hgignore")
                 for pat in l:
                     if pat != "\n":
                         self.ignorelist.append(re.compile(pat[:-1]))
@@ -370,6 +371,9 @@
         if f[0] == '/': f = f[1:]
         return filelog(self.opener, f)
 
+    def wfile(self, f, mode='r'):
+        return self.wopener(f, mode)
+
     def transaction(self):
         # save dirstate for undo
         try:
@@ -526,7 +530,7 @@
             dc = self.dirstate.copy()
 
         def fcmp(fn):
-            t1 = file(self.wjoin(fn)).read()
+            t1 = self.wfile(fn).read()
             t2 = self.file(fn).revision(mf[fn])
             return cmp(t1, t2)
 
@@ -991,13 +995,12 @@
             if f[0] == "/": continue
             self.ui.note("getting %s\n" % f)
             t = self.file(f).read(get[f])
-            wp = self.wjoin(f)
             try:
-                file(wp, "w").write(t)
+                self.wfile(f, "w").write(t)
             except IOError:
                 os.makedirs(os.path.dirname(wp))
-                file(wp, "w").write(t)
-            set_exec(wp, mf2[f])
+                self.wfile(f, "w").write(t)
+            set_exec(self.wjoin(f), mf2[f])
             self.dirstate.update([f], mode)
 
         # merge the tricky bits