##// END OF EJS Templates
store: refactor the fncache handling...
Benoit Boissinot -
r8530:03196ac9 default
parent child Browse files
Show More
@@ -214,37 +214,47 b' class encodedstore(basicstore):'
214 214 return (['requires', '00changelog.i'] +
215 215 [self.pathjoiner('store', f) for f in _data.split()])
216 216
217 def fncache(opener):
218 '''yields the entries in the fncache file'''
219 try:
220 fp = opener('fncache', mode='rb')
221 except IOError:
222 # skip nonexistent file
223 return
224 for n, line in enumerate(fp):
225 if (len(line) < 2) or (line[-1] != '\n'):
226 t = _('invalid entry in fncache, line %s') % (n + 1)
227 raise util.Abort(t)
228 yield line[:-1]
229 fp.close()
230
231 class fncacheopener(object):
217 class fncache(object):
232 218 def __init__(self, opener):
233 219 self.opener = opener
234 220 self.entries = None
235 221
236 def loadfncache(self):
237 self.entries = set(fncache(self.opener))
222 def _load(self):
223 '''fill the entries from the fncache file'''
224 self.entries = set()
225 try:
226 fp = self.opener('fncache', mode='rb')
227 except IOError:
228 # skip nonexistent file
229 return
230 for n, line in enumerate(fp):
231 if (len(line) < 2) or (line[-1] != '\n'):
232 t = _('invalid entry in fncache, line %s') % (n + 1)
233 raise util.Abort(t)
234 self.entries.add(line[:-1])
235 fp.close()
238 236
239 def __call__(self, path, mode='r', *args, **kw):
240 if mode not in ('r', 'rb') and path.startswith('data/'):
241 if self.entries is None:
242 self.loadfncache()
243 if path not in self.entries:
244 self.opener('fncache', 'ab').write(path + '\n')
245 # fncache may contain non-existent files after rollback / strip
246 self.entries.add(path)
247 return self.opener(hybridencode(path), mode, *args, **kw)
237 def rewrite(self, files):
238 fp = self.opener('fncache', mode='wb')
239 for p in files:
240 fp.write(p + '\n')
241 fp.close()
242 self.entries = set(files)
243
244 def add(self, fn):
245 if self.entries is None:
246 self._load()
247 self.opener('fncache', 'ab').write(fn + '\n')
248
249 def __contains__(self, fn):
250 if self.entries is None:
251 self._load()
252 return fn in self.entries
253
254 def __iter__(self):
255 if self.entries is None:
256 self._load()
257 return iter(self.entries)
248 258
249 259 class fncachestore(basicstore):
250 260 def __init__(self, path, opener, pathjoiner):
@@ -253,7 +263,15 b' class fncachestore(basicstore):'
253 263 self.createmode = _calcmode(self.path)
254 264 self._op = opener(self.path)
255 265 self._op.createmode = self.createmode
256 self.opener = fncacheopener(self._op)
266 self.fncache = fncache(self._op)
267
268 def fncacheopener(path, mode='r', *args, **kw):
269 if (mode not in ('r', 'rb')
270 and path.startswith('data/')
271 and path not in self.fncache):
272 self.fncache.add(path)
273 return self._op(hybridencode(path), mode, *args, **kw)
274 self.opener = fncacheopener
257 275
258 276 def join(self, f):
259 277 return self.pathjoiner(self.path, hybridencode(f))
@@ -263,7 +281,7 b' class fncachestore(basicstore):'
263 281 existing = []
264 282 pjoin = self.pathjoiner
265 283 spath = self.path
266 for f in fncache(self._op):
284 for f in self.fncache:
267 285 ef = hybridencode(f)
268 286 try:
269 287 st = os.stat(pjoin(spath, ef))
@@ -275,10 +293,7 b' class fncachestore(basicstore):'
275 293 if rewrite:
276 294 # rewrite fncache to remove nonexistent entries
277 295 # (may be caused by rollback / strip)
278 fp = self._op('fncache', mode='wb')
279 for p in existing:
280 fp.write(p + '\n')
281 fp.close()
296 self.fncache.rewrite(existing)
282 297
283 298 def copylist(self):
284 299 d = _data + ' dh fncache'
General Comments 0
You need to be logged in to leave comments. Login now