diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -9,13 +9,13 @@ from node import bin, hex, nullid, nullr import encoding def read(repo): - partial = {} + partial = branchcache() try: f = repo.opener("cache/branchheads") lines = f.read().split('\n') f.close() except (IOError, OSError): - return {}, nullid, nullrev + return branchcache(), nullid, nullrev try: last, lrev = lines.pop(0).split(" ", 1) @@ -37,7 +37,7 @@ def read(repo): except Exception, inst: if repo.ui.debugflag: repo.ui.warn(str(inst), '\n') - partial, last, lrev = {}, nullid, nullrev + partial, last, lrev = branchcache(), nullid, nullrev return partial, last, lrev def write(repo, branches, tip, tiprev): @@ -143,3 +143,7 @@ def updatecache(repo): update(repo, partial, ctxgen) repo._branchcache = partial repo._branchcachetip = tip + +class branchcache(dict): + """A dict like object that hold branches heads cache""" + diff --git a/mercurial/discovery.py b/mercurial/discovery.py --- a/mercurial/discovery.py +++ b/mercurial/discovery.py @@ -193,8 +193,9 @@ def _headssummary(repo, remote, outgoing # D. Update newmap with outgoing changes. # This will possibly add new heads and remove existing ones. - newmap = dict((branch, heads[1]) for branch, heads in headssum.iteritems() - if heads[0] is not None) + newmap = branchmap.branchcache((branch, heads[1]) + for branch, heads in headssum.iteritems() + if heads[0] is not None) branchmap.update(repo, newmap, missingctx) for branch, newheads in newmap.iteritems(): headssum[branch][1][:] = newheads diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -666,7 +666,7 @@ class localrepository(object): '''returns a dictionary {branch: [branchheads]}''' if self.changelog.filteredrevs: # some changeset are excluded we can't use the cache - bmap = {} + bmap = branchmap.branchcache() branchmap.update(self, bmap, (self[r] for r in self)) return bmap else: @@ -2495,7 +2495,7 @@ class localrepository(object): if rbheads: rtiprev = max((int(self.changelog.rev(node)) for node in rbheads)) - self._branchcache = rbranchmap + self._branchcache = branchmap.branchcache(rbranchmap) rtipnode = self._branchcachetip = self[rtiprev].node() branchmap.write(self, self._branchcache, rtipnode, rtiprev) self.invalidate()