[PATCH 05 of 10] branchmap: simplify write signature

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Dec 21 19:48:52 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1356138289 -3600
# Node ID dcd43ac7572d5d9eacb76ca577eb96d36a8cbb70
# Parent  090ada0acddb4486e94fba9c89e25b0624442d0f
branchmap: simplify write signature

All necessary data (cache value and key) are now stored in the branchcache
object. Any extra parameter is superfluous.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -40,15 +40,15 @@ def read(repo):
         if repo.ui.debugflag:
             repo.ui.warn(str(inst), '\n')
         partial = branchcache()
     return partial
 
-def write(repo, branches, tip, tiprev):
+def write(repo, cache):
     try:
         f = repo.opener("cache/branchheads", "w", atomictemp=True)
-        f.write("%s %s\n" % (hex(tip), tiprev))
-        for label, nodes in branches.iteritems():
+        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
@@ -131,11 +131,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.tipnode, partial.tiprev)
+        write(repo, partial)
     # 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:
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.tipnode, cache.tiprev)
+            branchmap.write(self, cache)
 
         # 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.tipnode, cache.tiprev)
+                    branchmap.write(self, cache)
             self.invalidate()
             return len(self.heads()) + 1
         finally:
             lock.release()
 


More information about the Mercurial-devel mailing list