[PATCH V2] store: invoke "osutil.listdir()" via vfs

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Oct 9 02:20:04 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1349767075 -32400
# Node ID ac92b7abbdf80985c8e3a9e24c7925bb510c2019
# Parent  3c775c5a6c03ed010ce2b85dd59968c63afc77b6
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.

diff -r 3c775c5a6c03 -r ac92b7abbdf8 mercurial/scmutil.py
--- a/mercurial/scmutil.py	Mon Oct 08 17:50:42 2012 -0500
+++ 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))
 
diff -r 3c775c5a6c03 -r ac92b7abbdf8 mercurial/store.py
--- a/mercurial/store.py	Mon Oct 08 17:50:42 2012 -0500
+++ 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:])


More information about the Mercurial-devel mailing list