changeset 19899:8c3dcbbfb5de

changelog: use "vfs.fstat()" instead of "util.fstat()" Just invoking "os.fstat()" with "file.fileno()" doesn't require non ANSI file API, because filename is not used for invocation of "os.fstat()". But "util.fstat()" should invoke "os.stat()" with "fp.name", if file object doesn't have "fileno()" method for portability, and "fp.name" may cause invocation of non ANSI file API. So, this patch makes the constructor of appender class invoke "util.fstat()" via vfs, to encapsulate filename handling.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 15 Oct 2013 00:51:04 +0900
parents 3f92e749d381
children 7c21e3398931
files mercurial/changelog.py mercurial/scmutil.py
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changelog.py	Tue Oct 15 00:51:04 2013 +0900
+++ b/mercurial/changelog.py	Tue Oct 15 00:51:04 2013 +0900
@@ -59,11 +59,12 @@
 class appender(object):
     '''the changelog index must be updated last on disk, so we use this class
     to delay writes to it'''
-    def __init__(self, fp, buf):
+    def __init__(self, vfs, name, mode, buf):
         self.data = buf
+        fp = vfs(name, mode)
         self.fp = fp
         self.offset = fp.tell()
-        self.size = util.fstat(fp).st_size
+        self.size = vfs.fstat(fp).st_size
 
     def end(self):
         return self.size + len("".join(self.data))
@@ -114,7 +115,7 @@
         if divert:
             return opener(name + ".a", mode.replace('a', 'w'))
         # otherwise, divert to memory
-        return appender(opener(name, mode), buf)
+        return appender(opener, name, mode, buf)
     return o
 
 class changelog(revlog.revlog):
--- a/mercurial/scmutil.py	Tue Oct 15 00:51:04 2013 +0900
+++ b/mercurial/scmutil.py	Tue Oct 15 00:51:04 2013 +0900
@@ -245,6 +245,9 @@
     def exists(self, path=None):
         return os.path.exists(self.join(path))
 
+    def fstat(self, fp):
+        return util.fstat(fp)
+
     def isdir(self, path=None):
         return os.path.isdir(self.join(path))