changeset 41566:eb7ce452e0fb

branchmap: updating triggers a write Rather than separate updating and writing, create a subclass that doesn't write on update. This minimises chances we forget to write out updates somewhere. This also makes refactoring and improving the branchmap functionality easier. Differential Revision: https://phab.mercurial-scm.org/D5636
author Martijn Pieters <mj@octobus.net>
date Mon, 21 Jan 2019 16:37:23 +0000
parents bf7fb97aecf1
children c795c462b1d6
files mercurial/branchmap.py mercurial/discovery.py
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Mon Jan 21 16:04:48 2019 +0000
+++ b/mercurial/branchmap.py	Mon Jan 21 16:37:23 2019 +0000
@@ -63,7 +63,6 @@
     revs.extend(cl.revs(start=bcache.tiprev + 1))
     if revs:
         bcache.update(repo, revs)
-        bcache.write(repo)
 
     assert bcache.validfor(repo), filtername
     repo._branchcaches[repo.filtername] = bcache
@@ -242,8 +241,9 @@
 
     def copy(self):
         """return an deep copy of the branchcache object"""
-        return branchcache(self, self.tipnode, self.tiprev, self.filteredhash,
-                           self._closednodes)
+        return type(self)(
+            self, self.tipnode, self.tiprev, self.filteredhash,
+            self._closednodes)
 
     def write(self, repo):
         try:
@@ -332,6 +332,15 @@
         repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n',
                     repo.filtername, duration)
 
+        self.write(repo)
+
+
+class remotebranchcache(branchcache):
+    """Branchmap info for a remote connection, should not write locally"""
+    def write(self, repo):
+        pass
+
+
 # Revision branch info cache
 
 _rbcversion = '-v1'
--- a/mercurial/discovery.py	Mon Jan 21 16:04:48 2019 +0000
+++ b/mercurial/discovery.py	Mon Jan 21 16:37:23 2019 +0000
@@ -238,7 +238,7 @@
 
     # D. Update newmap with outgoing changes.
     # This will possibly add new heads and remove existing ones.
-    newmap = branchmap.branchcache((branch, heads[1])
+    newmap = branchmap.remotebranchcache((branch, heads[1])
                                  for branch, heads in headssum.iteritems()
                                  if heads[0] is not None)
     newmap.update(repo, (ctx.rev() for ctx in missingctx))