@@ -7,17 +7,17 @@
from node import bin, hex, nullid, nullrev
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)
last, lrev = bin(last), int(lrev)
if lrev >= len(repo) or repo[lrev].node() != last:
@@ -35,11 +35,11 @@ def read(repo):
except KeyboardInterrupt:
raise
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):
try:
f = repo.opener("cache/branchheads", "w", atomictemp=True)
@@ -141,5 +141,9 @@ def updatecache(repo):
if lrev < tiprev:
ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev))
update(repo, partial, ctxgen)
repo._branchcache = partial
repo._branchcachetip = tip
+
+class branchcache(dict):
+ """A dict like object that hold branches heads cache"""
+
@@ -191,12 +191,13 @@ def _headssummary(repo, remote, outgoing
for branch in remotebranches - touchedbranches:
del headssum[branch]
# 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
return headssum
@@ -664,11 +664,11 @@ class localrepository(object):
def branchmap(self):
'''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:
branchmap.updatecache(self)
return self._branchcache
@@ -2493,11 +2493,11 @@ class localrepository(object):
rbheads.extend(bheads)
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()
return len(self.heads()) + 1
finally: