Patchwork [06,of,10] branchmap: extract write logic from localrepo

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 19, 2012, 1:53 p.m.
Message ID <1c902599a39b55fc6794.1355925202@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/196/
State Superseded, archived
Commit 526e7ec5c96efc69d043cfc2de7db6c1fc04233e
Headers show

Comments

Pierre-Yves David - Dec. 19, 2012, 1:53 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1355924771 -3600
# Node ID 1c902599a39b55fc6794aa56e9a366fbb9e02f47
# Parent  f5816e6bc7b28b668ebc1739a5e56936826558cc
branchmap: extract write logic from localrepo

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -2,5 +2,19 @@ 
 #
 # Copyright 2005-2007 Matt Mackall <mpm at selenic.com>
 #
 # 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
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -13,10 +13,11 @@  import scmutil, util, extensions, hook, 
 import match as matchmod
 import merge as mergemod
 import tags as tagsmod
 from lock import release
 import weakref, errno, os, time, inspect
+import branchmap
 propertycache = util.propertycache
 filecache = scmutil.filecache
 
 class repofilecache(filecache):
     """All filecache usage on repo are done for logic that should be unfiltered
@@ -664,11 +665,11 @@  class localrepository(object):
         # if lrev >  catip: we have uncachable element in `partial` can't write
         #                   on disk
         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)
         # update cache up to current tip
         tiprev = len(self) - 1
         if lrev < tiprev:
             ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev))
             self._updatebranchcache(partial, ctxgen)
@@ -742,22 +743,10 @@  class localrepository(object):
                 self.ui.warn(str(inst), '\n')
             partial, last, lrev = {}, nullid, nullrev
         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
         heads missing, this function updates partial to be correct.
         """
@@ -1551,12 +1540,12 @@  class localrepository(object):
         if newheadnodes:
             tiprev = len(self) - 1
             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
         # heads immediately after a strip/rollback.  That in turn
         # guarantees that "cachetip == currenttip" (comparing both rev
@@ -2606,11 +2595,11 @@  class localrepository(object):
 
                 self.branchcache = rbranchmap
                 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
         finally:
             lock.release()