[PATCH 06 of 10] branchmap: make write a method on the branchmap object
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Fri Dec 21 19:48:53 CST 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1356017323 -3600
# Node ID f0d56efaa35af94289119820179508e9546984a1
# Parent dcd43ac7572d5d9eacb76ca577eb96d36a8cbb70
branchmap: make write a method on the branchmap object
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -40,21 +40,10 @@ def read(repo):
if repo.ui.debugflag:
repo.ui.warn(str(inst), '\n')
partial = branchcache()
return partial
-def write(repo, cache):
- try:
- f = repo.opener("cache/branchheads", "w", atomictemp=True)
- f.write("%s %s\n" % (hex(cache.tipnode), cache.tiprev))
- for label, nodes in cache.iteritems():
- for node in nodes:
- f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
- f.close()
- except (IOError, OSError):
- pass
-
def update(repo, partial, ctxgen):
"""Given a branchhead cache, partial, that may have extra nodes or be
missing heads, and a generator of nodes that are at least a superset of
heads missing, this function updates partial to be correct.
"""
@@ -131,11 +120,11 @@ def updatecache(repo):
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)
partial.tiprev = catip
- write(repo, partial)
+ partial.write(repo)
# 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 partial.tiprev < tiprev:
@@ -150,5 +139,16 @@ class branchcache(dict):
def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev):
super(branchcache, self).__init__(entries)
self.tipnode = tipnode
self.tiprev = tiprev
+
+ def write(self, repo):
+ try:
+ f = repo.opener("cache/branchheads", "w", atomictemp=True)
+ f.write("%s %s\n" % (hex(self.tipnode), self.tiprev))
+ for label, nodes in self.iteritems():
+ for node in nodes:
+ f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
+ f.close()
+ except (IOError, OSError):
+ pass
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1438,11 +1438,11 @@ class localrepository(object):
if self.changelog.hasnode(node))
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.write(self)
# Ensure the persistent tag cache is updated. Doing it now
# means that the tag cache only has to worry about destroyed
# heads immediately after a strip/rollback. That in turn
# guarantees that "cachetip == currenttip" (comparing both rev
@@ -2496,11 +2496,11 @@ class localrepository(object):
for node in rbheads))
cache = branchmap.branchcache(rbranchmap,
self[rtiprev].node(),
rtiprev)
self._branchcache = cache
- branchmap.write(self, cache)
+ cache.write(self)
self.invalidate()
return len(self.heads()) + 1
finally:
lock.release()
More information about the Mercurial-devel
mailing list