mercurial/localrepo.py
changeset 18118 e70ff1e599f4
parent 18117 526e7ec5c96e
child 18119 5264464b5f68
equal deleted inserted replaced
18117:526e7ec5c96e 18118:e70ff1e599f4
     2 #
     2 #
     3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
     3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 from node import bin, hex, nullid, nullrev, short
     7 from node import hex, nullid, short
     8 from i18n import _
     8 from i18n import _
     9 import peer, changegroup, subrepo, discovery, pushkey, obsolete, repoview
     9 import peer, changegroup, subrepo, discovery, pushkey, obsolete, repoview
    10 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
    10 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
    11 import lock, transaction, store, encoding, base85
    11 import lock, transaction, store, encoding, base85
    12 import scmutil, util, extensions, hook, error, revset
    12 import scmutil, util, extensions, hook, error, revset
   669         if self._branchcache is not None and self._branchcachetip == tip:
   669         if self._branchcache is not None and self._branchcachetip == tip:
   670             return
   670             return
   671 
   671 
   672         oldtip = self._branchcachetip
   672         oldtip = self._branchcachetip
   673         if oldtip is None or oldtip not in cl.nodemap:
   673         if oldtip is None or oldtip not in cl.nodemap:
   674             partial, last, lrev = self._readbranchcache()
   674             partial, last, lrev = branchmap.read(self)
   675         else:
   675         else:
   676             lrev = cl.rev(oldtip)
   676             lrev = cl.rev(oldtip)
   677             partial = self._branchcache
   677             partial = self._branchcache
   678 
   678 
   679         catip = self._cacheabletip()
   679         catip = self._cacheabletip()
   727         the branch, open heads come before closed'''
   727         the branch, open heads come before closed'''
   728         bt = {}
   728         bt = {}
   729         for bn, heads in self.branchmap().iteritems():
   729         for bn, heads in self.branchmap().iteritems():
   730             bt[bn] = self._branchtip(heads)
   730             bt[bn] = self._branchtip(heads)
   731         return bt
   731         return bt
   732 
       
   733     @unfilteredmethod # Until we get a smarter cache management
       
   734     def _readbranchcache(self):
       
   735         partial = {}
       
   736         try:
       
   737             f = self.opener("cache/branchheads")
       
   738             lines = f.read().split('\n')
       
   739             f.close()
       
   740         except (IOError, OSError):
       
   741             return {}, nullid, nullrev
       
   742 
       
   743         try:
       
   744             last, lrev = lines.pop(0).split(" ", 1)
       
   745             last, lrev = bin(last), int(lrev)
       
   746             if lrev >= len(self) or self[lrev].node() != last:
       
   747                 # invalidate the cache
       
   748                 raise ValueError('invalidating branch cache (tip differs)')
       
   749             for l in lines:
       
   750                 if not l:
       
   751                     continue
       
   752                 node, label = l.split(" ", 1)
       
   753                 label = encoding.tolocal(label.strip())
       
   754                 if not node in self:
       
   755                     raise ValueError('invalidating branch cache because node '+
       
   756                                      '%s does not exist' % node)
       
   757                 partial.setdefault(label, []).append(bin(node))
       
   758         except KeyboardInterrupt:
       
   759             raise
       
   760         except Exception, inst:
       
   761             if self.ui.debugflag:
       
   762                 self.ui.warn(str(inst), '\n')
       
   763             partial, last, lrev = {}, nullid, nullrev
       
   764         return partial, last, lrev
       
   765 
   732 
   766     @unfilteredmethod # Until we get a smarter cache management
   733     @unfilteredmethod # Until we get a smarter cache management
   767     def _updatebranchcache(self, partial, ctxgen):
   734     def _updatebranchcache(self, partial, ctxgen):
   768         """Given a branchhead cache, partial, that may have extra nodes or be
   735         """Given a branchhead cache, partial, that may have extra nodes or be
   769         missing heads, and a generator of nodes that are at least a superset of
   736         missing heads, and a generator of nodes that are at least a superset of