branchmap: add the tiprev (cache key) on the branchmap object
The actual cache key used on disk is the (tipnode, tiprev) pair. There is no
reason not to use the revision number for the in memory version.
--- a/mercurial/branchmap.py Sat Dec 22 01:59:05 2012 +0100
+++ b/mercurial/branchmap.py Sat Dec 22 02:06:26 2012 +0100
@@ -15,7 +15,7 @@
lines = f.read().split('\n')
f.close()
except (IOError, OSError):
- return branchcache(), nullrev
+ return branchcache()
try:
last, lrev = lines.pop(0).split(" ", 1)
@@ -33,13 +33,14 @@
'%s does not exist' % node)
partial.setdefault(label, []).append(bin(node))
partial.tipnode = last
+ partial.tiprev = lrev
except KeyboardInterrupt:
raise
except Exception, inst:
if repo.ui.debugflag:
repo.ui.warn(str(inst), '\n')
- partial, lrev = branchcache(), nullrev
- return partial, lrev
+ partial = branchcache()
+ return partial
def write(repo, branches, tip, tiprev):
try:
@@ -121,33 +122,33 @@
return
if partial is None or partial.tipnode not in cl.nodemap:
- partial, lrev = read(repo)
- else:
- lrev = cl.rev(partial.tipnode)
+ partial = read(repo)
catip = repo._cacheabletip()
- # if lrev == catip: cache is already up to date
- # if lrev > catip: we have uncachable element in `partial` can't write
- # on disk
- if lrev < catip:
- ctxgen = (repo[r] for r in cl.revs(lrev + 1, catip))
+ # if partial.tiprev == catip: cache is already up to date
+ # if partial.tiprev > catip: we have uncachable element in `partial` can't
+ # write on disk
+ if partial.tiprev < catip:
+ ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip))
update(repo, partial, ctxgen)
partial.tipnode = cl.node(catip)
- write(repo, partial, partial.tipnode, catip)
- lrev = catip
+ partial.tiprev = catip
+ write(repo, partial, partial.tipnode, partial.tiprev)
# If cacheable tip were lower than actual tip, we need to update the
# cache up to tip. This update (from cacheable to actual tip) is not
# written to disk since it's not cacheable.
tiprev = len(repo) - 1
- if lrev < tiprev:
- ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev))
+ if partial.tiprev < tiprev:
+ ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, tiprev))
update(repo, partial, ctxgen)
partial.tipnode = cl.node(tiprev)
+ partial.tiprev = tiprev
repo._branchcache = partial
class branchcache(dict):
"""A dict like object that hold branches heads cache"""
- def __init__(self, entries=(), tipnode=nullid):
+ def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev):
super(branchcache, self).__init__(entries)
self.tipnode = tipnode
+ self.tiprev = tiprev
--- a/mercurial/localrepo.py Sat Dec 22 01:59:05 2012 +0100
+++ b/mercurial/localrepo.py Sat Dec 22 02:06:26 2012 +0100
@@ -1434,13 +1434,13 @@
# it, Otherwise, since nodes were destroyed, the cache is stale and this
# will be caught the next time it is read.
if newheadnodes:
- tiprev = len(self) - 1
ctxgen = (self[node] for node in newheadnodes
if self.changelog.hasnode(node))
- branchmap.update(self, self._branchcache, ctxgen)
- self._branchcache.tipnode = self.changelog.tip()
- branchmap.write(self, self._branchcache, self._branchcache.tipnode,
- tiprev)
+ cache = self._branchcache
+ branchmap.update(self, cache, ctxgen)
+ cache.tipnode = self.changelog.tip()
+ cache.tiprev = self.changelog.rev(cache.tipnode)
+ branchmap.write(self, cache, cache.tipnode, cache.tiprev)
# Ensure the persistent tag cache is updated. Doing it now
# means that the tag cache only has to worry about destroyed
@@ -2495,9 +2495,10 @@
rtiprev = max((int(self.changelog.rev(node))
for node in rbheads))
cache = branchmap.branchcache(rbranchmap,
- self[rtiprev].node())
+ self[rtiprev].node(),
+ rtiprev)
self._branchcache = cache
- branchmap.write(self, cache, cache.tipnode, rtiprev)
+ branchmap.write(self, cache, cache.tipnode, cache.tiprev)
self.invalidate()
return len(self.heads()) + 1
finally: