##// 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 return (['requires', '00changelog.i'] +
214 return (['requires', '00changelog.i'] +
215 [self.pathjoiner('store', f) for f in _data.split()])
215 [self.pathjoiner('store', f) for f in _data.split()])
216
216
217 def fncache(opener):
217 class fncache(object):
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):
232 def __init__(self, opener):
218 def __init__(self, opener):
233 self.opener = opener
219 self.opener = opener
234 self.entries = None
220 self.entries = None
235
221
236 def loadfncache(self):
222 def _load(self):
237 self.entries = set(fncache(self.opener))
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):
237 def rewrite(self, files):
240 if mode not in ('r', 'rb') and path.startswith('data/'):
238 fp = self.opener('fncache', mode='wb')
241 if self.entries is None:
239 for p in files:
242 self.loadfncache()
240 fp.write(p + '\n')
243 if path not in self.entries:
241 fp.close()
244 self.opener('fncache', 'ab').write(path + '\n')
242 self.entries = set(files)
245 # fncache may contain non-existent files after rollback / strip
243
246 self.entries.add(path)
244 def add(self, fn):
247 return self.opener(hybridencode(path), mode, *args, **kw)
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 class fncachestore(basicstore):
259 class fncachestore(basicstore):
250 def __init__(self, path, opener, pathjoiner):
260 def __init__(self, path, opener, pathjoiner):
@@ -253,7 +263,15 b' class fncachestore(basicstore):'
253 self.createmode = _calcmode(self.path)
263 self.createmode = _calcmode(self.path)
254 self._op = opener(self.path)
264 self._op = opener(self.path)
255 self._op.createmode = self.createmode
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 def join(self, f):
276 def join(self, f):
259 return self.pathjoiner(self.path, hybridencode(f))
277 return self.pathjoiner(self.path, hybridencode(f))
@@ -263,7 +281,7 b' class fncachestore(basicstore):'
263 existing = []
281 existing = []
264 pjoin = self.pathjoiner
282 pjoin = self.pathjoiner
265 spath = self.path
283 spath = self.path
266 for f in fncache(self._op):
284 for f in self.fncache:
267 ef = hybridencode(f)
285 ef = hybridencode(f)
268 try:
286 try:
269 st = os.stat(pjoin(spath, ef))
287 st = os.stat(pjoin(spath, ef))
@@ -275,10 +293,7 b' class fncachestore(basicstore):'
275 if rewrite:
293 if rewrite:
276 # rewrite fncache to remove nonexistent entries
294 # rewrite fncache to remove nonexistent entries
277 # (may be caused by rollback / strip)
295 # (may be caused by rollback / strip)
278 fp = self._op('fncache', mode='wb')
296 self.fncache.rewrite(existing)
279 for p in existing:
280 fp.write(p + '\n')
281 fp.close()
282
297
283 def copylist(self):
298 def copylist(self):
284 d = _data + ' dh fncache'
299 d = _data + ' dh fncache'
General Comments 0
You need to be logged in to leave comments. Login now