15 demandload(globals(), "os revlog time util") |
15 demandload(globals(), "os revlog time util") |
16 |
16 |
17 class localrepository(repo.repository): |
17 class localrepository(repo.repository): |
18 capabilities = ('lookup', 'changegroupsubset') |
18 capabilities = ('lookup', 'changegroupsubset') |
19 supported = ('revlogv1', 'store') |
19 supported = ('revlogv1', 'store') |
|
20 branchcache_features = ('unnamed',) |
20 |
21 |
21 def __del__(self): |
22 def __del__(self): |
22 self.transhandle = None |
23 self.transhandle = None |
23 def __init__(self, parentui, path=None, create=0): |
24 def __init__(self, parentui, path=None, create=0): |
24 repo.repository.__init__(self) |
25 repo.repository.__init__(self) |
374 partial = {} |
375 partial = {} |
375 try: |
376 try: |
376 f = self.opener("branches.cache") |
377 f = self.opener("branches.cache") |
377 lines = f.read().split('\n') |
378 lines = f.read().split('\n') |
378 f.close() |
379 f.close() |
|
380 features = lines.pop(0).strip() |
|
381 if not features.startswith('features: '): |
|
382 raise ValueError(_('branch cache: no features specified')) |
|
383 features = features.split(' ', 1)[1].split() |
|
384 missing_features = [] |
|
385 for feature in self.branchcache_features: |
|
386 try: |
|
387 features.remove(feature) |
|
388 except ValueError, inst: |
|
389 missing_features.append(feature) |
|
390 if missing_features: |
|
391 raise ValueError(_('branch cache: missing features: %s') |
|
392 % ', '.join(missing_features)) |
|
393 if features: |
|
394 raise ValueError(_('branch cache: unknown features: %s') |
|
395 % ', '.join(features)) |
379 last, lrev = lines.pop(0).split(" ", 1) |
396 last, lrev = lines.pop(0).split(" ", 1) |
380 last, lrev = bin(last), int(lrev) |
397 last, lrev = bin(last), int(lrev) |
381 if not (lrev < self.changelog.count() and |
398 if not (lrev < self.changelog.count() and |
382 self.changelog.node(lrev) == last): # sanity check |
399 self.changelog.node(lrev) == last): # sanity check |
383 # invalidate the cache |
400 # invalidate the cache |
395 return partial, last, lrev |
412 return partial, last, lrev |
396 |
413 |
397 def _writebranchcache(self, branches, tip, tiprev): |
414 def _writebranchcache(self, branches, tip, tiprev): |
398 try: |
415 try: |
399 f = self.opener("branches.cache", "w") |
416 f = self.opener("branches.cache", "w") |
|
417 f.write(" features: %s\n" % ' '.join(self.branchcache_features)) |
400 f.write("%s %s\n" % (hex(tip), tiprev)) |
418 f.write("%s %s\n" % (hex(tip), tiprev)) |
401 for label, node in branches.iteritems(): |
419 for label, node in branches.iteritems(): |
402 f.write("%s %s\n" % (hex(node), label)) |
420 f.write("%s %s\n" % (hex(node), label)) |
403 except IOError: |
421 except IOError: |
404 pass |
422 pass |