comparison mercurial/changelog.py @ 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 7d4219512823
comparison
equal deleted inserted replaced
19898:3f92e749d381 19899:8c3dcbbfb5de
57 return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n') 57 return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
58 58
59 class appender(object): 59 class appender(object):
60 '''the changelog index must be updated last on disk, so we use this class 60 '''the changelog index must be updated last on disk, so we use this class
61 to delay writes to it''' 61 to delay writes to it'''
62 def __init__(self, fp, buf): 62 def __init__(self, vfs, name, mode, buf):
63 self.data = buf 63 self.data = buf
64 fp = vfs(name, mode)
64 self.fp = fp 65 self.fp = fp
65 self.offset = fp.tell() 66 self.offset = fp.tell()
66 self.size = util.fstat(fp).st_size 67 self.size = vfs.fstat(fp).st_size
67 68
68 def end(self): 69 def end(self):
69 return self.size + len("".join(self.data)) 70 return self.size + len("".join(self.data))
70 def tell(self): 71 def tell(self):
71 return self.offset 72 return self.offset
112 if name != target: 113 if name != target:
113 return opener(name, mode) 114 return opener(name, mode)
114 if divert: 115 if divert:
115 return opener(name + ".a", mode.replace('a', 'w')) 116 return opener(name + ".a", mode.replace('a', 'w'))
116 # otherwise, divert to memory 117 # otherwise, divert to memory
117 return appender(opener(name, mode), buf) 118 return appender(opener, name, mode, buf)
118 return o 119 return o
119 120
120 class changelog(revlog.revlog): 121 class changelog(revlog.revlog):
121 def __init__(self, opener): 122 def __init__(self, opener):
122 revlog.revlog.__init__(self, opener, "00changelog.i") 123 revlog.revlog.__init__(self, opener, "00changelog.i")