changeset 18117:526e7ec5c96e

branchmap: extract write logic from localrepo
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Thu, 20 Dec 2012 13:37:37 +0100
parents bcee63733aad
children e70ff1e599f4
files mercurial/branchmap.py mercurial/localrepo.py
diffstat 2 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Wed Dec 19 14:43:33 2012 +0100
+++ b/mercurial/branchmap.py	Thu Dec 20 13:37:37 2012 +0100
@@ -4,3 +4,17 @@
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
+
+from node import hex
+import encoding
+
+def write(repo, branches, tip, tiprev):
+    try:
+        f = repo.opener("cache/branchheads", "w", atomictemp=True)
+        f.write("%s %s\n" % (hex(tip), tiprev))
+        for label, nodes in branches.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	Wed Dec 19 14:43:33 2012 +0100
+++ b/mercurial/localrepo.py	Thu Dec 20 13:37:37 2012 +0100
@@ -15,6 +15,7 @@
 import tags as tagsmod
 from lock import release
 import weakref, errno, os, time, inspect
+import branchmap
 propertycache = util.propertycache
 filecache = scmutil.filecache
 
@@ -682,7 +683,7 @@
         if lrev < catip:
             ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
             self._updatebranchcache(partial, ctxgen)
-            self._writebranchcache(partial, cl.node(catip), catip)
+            branchmap.write(self, partial, cl.node(catip), catip)
             lrev = catip
         # 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
@@ -763,18 +764,6 @@
         return partial, last, lrev
 
     @unfilteredmethod # Until we get a smarter cache management
-    def _writebranchcache(self, branches, tip, tiprev):
-        try:
-            f = self.opener("cache/branchheads", "w", atomictemp=True)
-            f.write("%s %s\n" % (hex(tip), tiprev))
-            for label, nodes in branches.iteritems():
-                for node in nodes:
-                    f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
-            f.close()
-        except (IOError, OSError):
-            pass
-
-    @unfilteredmethod # Until we get a smarter cache management
     def _updatebranchcache(self, 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
@@ -1578,8 +1567,8 @@
             ctxgen = (self[node] for node in newheadnodes
                       if self.changelog.hasnode(node))
             self._updatebranchcache(self._branchcache, ctxgen)
-            self._writebranchcache(self._branchcache, self.changelog.tip(),
-                                   tiprev)
+            branchmap.write(self, self._branchcache, self.changelog.tip(),
+                            tiprev)
 
         # Ensure the persistent tag cache is updated.  Doing it now
         # means that the tag cache only has to worry about destroyed
@@ -2634,7 +2623,7 @@
                 if rbheads:
                     rtiprev = max((int(self.changelog.rev(node))
                             for node in rbheads))
-                    self._writebranchcache(self.branchcache,
+                    branchmap.write(self, self.branchcache,
                             self[rtiprev].node(), rtiprev)
             self.invalidate()
             return len(self.heads()) + 1