# HG changeset patch # User FUJIWARA Katsunori # Date 2013-10-14 15:51:04 # Node ID 8c3dcbbfb5deaa2385e5166542a5c8a6fbd6df81 # Parent 3f92e749d381575a5313963919b924b8bc64a178 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. diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -59,11 +59,12 @@ def stripdesc(desc): 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 @@ def delayopener(opener, target, divert, 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): diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -245,6 +245,9 @@ class abstractvfs(object): 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))