changeset 17161:be016e96117a

localrepo: use file API via vfs while ensuring repository directory As a part of migration to vfs, this patch invokes some file API indirectly via vfs, while ensuring repository directory in the constructor of "localrepository" class. New file API are added to "scmutil.abstractopener" class, because they are also used via other derived classes than "scmutil.opener". But "join()" is not yet defined other than "scmutil.opener" class, because it should not be used via other opener classes yet.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 06 Jul 2012 18:45:27 +0900
parents 22b9b1d2f5d4
children 868c256cb51b
files mercurial/localrepo.py mercurial/scmutil.py
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Fri Jul 06 18:45:27 2012 +0900
+++ b/mercurial/localrepo.py	Fri Jul 06 18:45:27 2012 +0900
@@ -58,14 +58,14 @@
         except IOError:
             pass
 
-        if not os.path.isdir(self.path):
+        if not self.vfs.isdir():
             if create:
-                if not os.path.exists(self.root):
-                    util.makedirs(self.root)
-                util.makedir(self.path, notindexed=True)
+                if not self.wvfs.exists():
+                    self.wvfs.makedirs()
+                self.vfs.makedir(notindexed=True)
                 requirements = self._baserequirements(create)
                 if self.ui.configbool('format', 'usestore', True):
-                    os.mkdir(os.path.join(self.path, "store"))
+                    self.vfs.mkdir("store")
                     requirements.append("store")
                     if self.ui.configbool('format', 'usefncache', True):
                         requirements.append("fncache")
--- a/mercurial/scmutil.py	Fri Jul 06 18:45:27 2012 +0900
+++ b/mercurial/scmutil.py	Fri Jul 06 18:45:27 2012 +0900
@@ -190,6 +190,21 @@
         finally:
             fp.close()
 
+    def mkdir(self, path=None):
+        return os.mkdir(self.join(path))
+
+    def exists(self, path=None):
+        return os.path.exists(self.join(path))
+
+    def isdir(self, path=None):
+        return os.path.isdir(self.join(path))
+
+    def makedir(self, path=None, notindexed=True):
+        return util.makedir(self.join(path), notindexed)
+
+    def makedirs(self, path=None, mode=None):
+        return util.makedirs(self.join(path), mode)
+
 class opener(abstractopener):
     '''Open files relative to a base directory
 
@@ -293,7 +308,10 @@
         self.auditor(path)
 
     def join(self, path):
-        return os.path.join(self.base, path)
+        if path:
+            return os.path.join(self.base, path)
+        else:
+            return self.base
 
 class filteropener(abstractopener):
     '''Wrapper opener for filtering filenames with a function.'''