Show More
@@ -214,10 +214,16 b' class encodedstore(basicstore):' | |||
|
214 | 214 | return (['requires', '00changelog.i'] + |
|
215 | 215 | [self.pathjoiner('store', f) for f in _data.split()]) |
|
216 | 216 | |
|
217 |
|
|
|
218 | '''yields the entries in the fncache file''' | |
|
217 | class fncache(object): | |
|
218 | def __init__(self, opener): | |
|
219 | self.opener = opener | |
|
220 | self.entries = None | |
|
221 | ||
|
222 | def _load(self): | |
|
223 | '''fill the entries from the fncache file''' | |
|
224 | self.entries = set() | |
|
219 | 225 | try: |
|
220 | fp = opener('fncache', mode='rb') | |
|
226 | fp = self.opener('fncache', mode='rb') | |
|
221 | 227 | except IOError: |
|
222 | 228 | # skip nonexistent file |
|
223 | 229 | return |
@@ -225,26 +231,30 b' def fncache(opener):' | |||
|
225 | 231 | if (len(line) < 2) or (line[-1] != '\n'): |
|
226 | 232 | t = _('invalid entry in fncache, line %s') % (n + 1) |
|
227 | 233 | raise util.Abort(t) |
|
228 |
|
|
|
234 | self.entries.add(line[:-1]) | |
|
229 | 235 | fp.close() |
|
230 | 236 | |
|
231 | class fncacheopener(object): | |
|
232 | def __init__(self, opener): | |
|
233 | self.opener = opener | |
|
234 | self.entries = None | |
|
235 | ||
|
236 | def loadfncache(self): | |
|
237 | self.entries = set(fncache(self.opener)) | |
|
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) | |
|
238 | 243 | |
|
239 | def __call__(self, path, mode='r', *args, **kw): | |
|
240 | if mode not in ('r', 'rb') and path.startswith('data/'): | |
|
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): | |
|
241 | 250 |
|
|
242 |
|
|
|
243 |
|
|
|
244 | self.opener('fncache', 'ab').write(path + '\n') | |
|
245 | # fncache may contain non-existent files after rollback / strip | |
|
246 |
|
|
|
247 | return self.opener(hybridencode(path), mode, *args, **kw) | |
|
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. |
|
|
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 |
|
|
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 |
|
|
|
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