mercurial/localrepo.py
changeset 4205 a7af0eeae8a3
parent 4204 f9bbcebcacea
child 4206 0b48e3985765
equal deleted inserted replaced
4204:f9bbcebcacea 4205:a7af0eeae8a3
    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 = ('default',)
       
    21 
    20 
    22     def __del__(self):
    21     def __del__(self):
    23         self.transhandle = None
    22         self.transhandle = None
    24     def __init__(self, parentui, path=None, create=0):
    23     def __init__(self, parentui, path=None, create=0):
    25         repo.repository.__init__(self)
    24         repo.repository.__init__(self)
   372         return self.branchcache
   371         return self.branchcache
   373 
   372 
   374     def _readbranchcache(self):
   373     def _readbranchcache(self):
   375         partial = {}
   374         partial = {}
   376         try:
   375         try:
   377             f = self.opener("branches.cache")
   376             f = self.opener("branch.cache")
   378             lines = f.read().split('\n')
   377             lines = f.read().split('\n')
   379             f.close()
   378             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))
       
   396             last, lrev = lines.pop(0).split(" ", 1)
   379             last, lrev = lines.pop(0).split(" ", 1)
   397             last, lrev = bin(last), int(lrev)
   380             last, lrev = bin(last), int(lrev)
   398             if not (lrev < self.changelog.count() and
   381             if not (lrev < self.changelog.count() and
   399                     self.changelog.node(lrev) == last): # sanity check
   382                     self.changelog.node(lrev) == last): # sanity check
   400                 # invalidate the cache
   383                 # invalidate the cache
   411             partial, last, lrev = {}, nullid, nullrev
   394             partial, last, lrev = {}, nullid, nullrev
   412         return partial, last, lrev
   395         return partial, last, lrev
   413 
   396 
   414     def _writebranchcache(self, branches, tip, tiprev):
   397     def _writebranchcache(self, branches, tip, tiprev):
   415         try:
   398         try:
   416             f = self.opener("branches.cache", "w")
   399             f = self.opener("branch.cache", "w")
   417             f.write(" features: %s\n" % ' '.join(self.branchcache_features))
       
   418             f.write("%s %s\n" % (hex(tip), tiprev))
   400             f.write("%s %s\n" % (hex(tip), tiprev))
   419             for label, node in branches.iteritems():
   401             for label, node in branches.iteritems():
   420                 f.write("%s %s\n" % (hex(node), label))
   402                 f.write("%s %s\n" % (hex(node), label))
   421         except IOError:
   403         except IOError:
   422             pass
   404             pass