store: invoke "osutil.listdir()" via vfs
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Tue, 09 Oct 2012 16:17:55 +0900
changeset 17747 aad3bce98f76
parent 17746 6d218e47cf9b
child 17751 4871c1f343fa
store: invoke "osutil.listdir()" via vfs This patch invokes "osutil.listdir()" via vfs object. The function added newly to "abstractvfs" is named not as "listdir()" but as "readdir()", because: - "os.listdir()" seems to be more familiar as "listdir()" than "osutil.listdir()" - "osutil.listdir()" returns also type of each files like "readdir()" POSIX API: even though "d_type" field of "dirent" structure is defined mainly only on BSD/Linux This patch invokes "osutil.listdir()" via "rawvfs" object to avoid filename encoding, because the path passed to "osutil.listdir()" shouldn't be encoded. This patch also omits importing "osutil" module, because it is no longer used.
mercurial/scmutil.py
mercurial/store.py
--- a/mercurial/scmutil.py	Thu Sep 13 23:50:45 2012 -0700
+++ b/mercurial/scmutil.py	Tue Oct 09 16:17:55 2012 +0900
@@ -219,6 +219,9 @@
     def mkdir(self, path=None):
         return os.mkdir(self.join(path))
 
+    def readdir(self, path=None, stat=None, skip=None):
+        return osutil.listdir(self.join(path), stat, skip)
+
     def stat(self, path=None):
         return os.stat(self.join(path))
 
--- a/mercurial/store.py	Thu Sep 13 23:50:45 2012 -0700
+++ b/mercurial/store.py	Tue Oct 09 16:17:55 2012 +0900
@@ -6,7 +6,7 @@
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import osutil, scmutil, util, parsers
+import scmutil, util, parsers
 import os, stat, errno
 
 _sha = util.sha1
@@ -311,9 +311,10 @@
         l = []
         if self.rawvfs.isdir(path):
             visit = [path]
+            readdir = self.rawvfs.readdir
             while visit:
                 p = visit.pop()
-                for f, kind, st in osutil.listdir(p, stat=True):
+                for f, kind, st in readdir(p, stat=True):
                     fp = p + '/' + f
                     if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
                         n = util.pconvert(fp[striplen:])