comparison mercurial/scmutil.py @ 23368:bf8c3172255c

vfs: add "readlines" and "tryreadlines" This patch allows "readlines" and "tryreadlines" to take "mode" argument, because "subrepo" requires to read files not in "rb" (binary, default for vfs) but in "r" (text) mode in subsequent patch.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 19 Nov 2014 18:35:14 +0900
parents 9f4778027bc2
children 46265d0f0c7b
comparison
equal deleted inserted replaced
23367:115af8de76a4 23368:bf8c3172255c
186 except IOError, inst: 186 except IOError, inst:
187 if inst.errno != errno.ENOENT: 187 if inst.errno != errno.ENOENT:
188 raise 188 raise
189 return "" 189 return ""
190 190
191 def tryreadlines(self, path, mode='rb'):
192 '''gracefully return an empty array for missing files'''
193 try:
194 return self.readlines(path, mode=mode)
195 except IOError, inst:
196 if inst.errno != errno.ENOENT:
197 raise
198 return []
199
191 def open(self, path, mode="r", text=False, atomictemp=False): 200 def open(self, path, mode="r", text=False, atomictemp=False):
192 self.open = self.__call__ 201 self.open = self.__call__
193 return self.__call__(path, mode, text, atomictemp) 202 return self.__call__(path, mode, text, atomictemp)
194 203
195 def read(self, path): 204 def read(self, path):
196 fp = self(path, 'rb') 205 fp = self(path, 'rb')
197 try: 206 try:
198 return fp.read() 207 return fp.read()
208 finally:
209 fp.close()
210
211 def readlines(self, path, mode='rb'):
212 fp = self(path, mode=mode)
213 try:
214 return fp.readlines()
199 finally: 215 finally:
200 fp.close() 216 fp.close()
201 217
202 def write(self, path, data): 218 def write(self, path, data):
203 fp = self(path, 'wb') 219 fp = self(path, 'wb')