changeset 18128:f0d56efaa35a

branchmap: make write a method on the branchmap object
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 20 Dec 2012 16:28:43 +0100
parents dcd43ac7572d
children 3264d3ce53a0
files mercurial/branchmap.py mercurial/localrepo.py
diffstat 2 files changed, 14 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Sat Dec 22 02:04:49 2012 +0100
+++ b/mercurial/branchmap.py	Thu Dec 20 16:28:43 2012 +0100
@@ -42,17 +42,6 @@
         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
@@ -133,7 +122,7 @@
         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.
@@ -152,3 +141,14 @@
         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
--- a/mercurial/localrepo.py	Sat Dec 22 02:04:49 2012 +0100
+++ b/mercurial/localrepo.py	Thu Dec 20 16:28:43 2012 +0100
@@ -1440,7 +1440,7 @@
             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
@@ -2498,7 +2498,7 @@
                                                   self[rtiprev].node(),
                                                   rtiprev)
                     self._branchcache = cache
-                    branchmap.write(self, cache)
+                    cache.write(self)
             self.invalidate()
             return len(self.heads()) + 1
         finally: