changeset 24378:9347c15d8136

revbranchcache: write cache even during read operations Previously we would only actually write the revbranchcache to disk if we were in the middle of a write operation (like commit). Now we will also write it during any read operation. The cache knows how to invalidate itself, so it shouldn't become corrupt if multiple writers try at once (and the write-on-read behavior/risk is the same as all our other caches).
author Durham Goode <durham@fb.com>
date Tue, 24 Feb 2015 18:43:31 -0800
parents 656f93ce66d5
children 8c445d8a915b
files mercurial/branchmap.py mercurial/localrepo.py tests/test-branches.t tests/test-rebase-conflicts.t
diffstat 4 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Tue Feb 10 20:06:12 2015 -0800
+++ b/mercurial/branchmap.py	Tue Feb 24 18:43:31 2015 -0800
@@ -97,9 +97,6 @@
         partial.update(repo, revs)
         partial.write(repo)
 
-    if repo._revbranchcache is not None:
-        repo._revbranchcache.write()
-
     assert partial.validfor(repo), filtername
     repo._branchcaches[repo.filtername] = partial
 
--- a/mercurial/localrepo.py	Tue Feb 10 20:06:12 2015 -0800
+++ b/mercurial/localrepo.py	Tue Feb 24 18:43:31 2015 -0800
@@ -303,7 +303,11 @@
         self.names = namespaces.namespaces()
 
     def close(self):
-        pass
+        self._writecaches()
+
+    def _writecaches(self):
+        if self._revbranchcache:
+            self._revbranchcache.write()
 
     def _restrictcapabilities(self, caps):
         # bundle2 is not ready for prime time, drop it unless explicitly
--- a/tests/test-branches.t	Tue Feb 10 20:06:12 2015 -0800
+++ b/tests/test-branches.t	Tue Feb 24 18:43:31 2015 -0800
@@ -561,8 +561,8 @@
 recovery from invalid cache revs file with trailing data
   $ echo >> .hg/cache/rbc-revs-v1
   $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
+  5
   truncating cache/rbc-revs-v1 to 120
-  5
   $ f --size .hg/cache/rbc-revs*
   .hg/cache/rbc-revs-v1: size=120
 recovery from invalid cache file with partial last record
@@ -571,8 +571,8 @@
   $ f --size .hg/cache/rbc-revs*
   .hg/cache/rbc-revs-v1: size=119
   $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
+  5
   truncating cache/rbc-revs-v1 to 112
-  5
   $ f --size .hg/cache/rbc-revs*
   .hg/cache/rbc-revs-v1: size=120
 recovery from invalid cache file with missing record - no truncation
@@ -590,11 +590,11 @@
   $ f -qDB 112 rbc-revs-v1 >> .hg/cache/rbc-revs-v1
   $ f --size .hg/cache/rbc-revs*
   .hg/cache/rbc-revs-v1: size=120
-  $ hg log -r 'branch(.)' -T '{rev} '
-  3 4 8 9 10 11 12 13  (no-eol)
+  $ hg log -r 'branch(.)' -T '{rev} ' --debug
+  3 4 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 8
   $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
-  truncating cache/rbc-revs-v1 to 8
   5
+  truncating cache/rbc-revs-v1 to 104
   $ f --size --hexdump --bytes=16 .hg/cache/rbc-revs*
   .hg/cache/rbc-revs-v1: size=120
   0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....|
--- a/tests/test-rebase-conflicts.t	Tue Feb 10 20:06:12 2015 -0800
+++ b/tests/test-rebase-conflicts.t	Tue Feb 24 18:43:31 2015 -0800
@@ -322,6 +322,6 @@
   files: 1/1 chunks (100.00%)
   added 2 changesets with 2 changes to 1 files
   invalid branchheads cache (served): tip differs
-  truncating cache/rbc-revs-v1 to 72
   rebase completed
   updating the branch cache
+  truncating cache/rbc-revs-v1 to 72