changeset 51903:9f7cf869e9f4

rev-branch-cache: add a way to force rewrite of the cache This seems useful to be able to do this, for example during strip. This align with the intended expressed in the `test-branches.t` test. This will help use being more confident about future changes in the series.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 23 Sep 2024 23:52:45 +0200
parents 1eb2317c1762
children 7032da075572
files mercurial/branching/rev_cache.py mercurial/repair.py tests/test-rebase-conflicts.t tests/test-strip.t
diffstat 4 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branching/rev_cache.py	Tue Sep 24 00:01:30 2024 +0200
+++ b/mercurial/branching/rev_cache.py	Mon Sep 23 23:52:45 2024 +0200
@@ -170,6 +170,7 @@
             self._names = []
         self._rbcnamescount = len(self._names)  # number of names read at
         # _rbcsnameslen
+        self._force_overwrite = False
 
     def _clear(self):
         self._rbcsnameslen = 0
@@ -178,6 +179,12 @@
         self._rbcrevslen = len(self._repo.changelog)
         self._rbcrevs = rbcrevs(bytearray(self._rbcrevslen * _rbcrecsize))
         util.clearcachedproperty(self, b'_namesreverse')
+        self._force_overwrite = True
+
+    def invalidate(self, rev=0):
+        self._rbcrevslen = rev
+        self._rbcrevs.truncate(rev)
+        self._force_overwrite = True
 
     @util.propertycache
     def _namesreverse(self):
@@ -292,7 +299,7 @@
 
             # write the new revs
             start = self._rbcrevslen * _rbcrecsize
-            if start != len(self._rbcrevs):
+            if self._force_overwrite or start != len(self._rbcrevs):
                 step = b''
                 if wlock is None:
                     wlock = repo.wlock(wait=False)
@@ -335,6 +342,8 @@
     def _writerevs(self, repo, start):
         """write the new revs to revbranchcache"""
         revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize)
+        if self._force_overwrite:
+            start = 0
         with repo.cachevfs.open(_rbcrevs, b'ab') as f:
             current_size = f.tell()
             if current_size < start:
@@ -348,3 +357,4 @@
             end = revs * _rbcrecsize
             f.write(self._rbcrevs.slice(start, end))
         self._rbcrevslen = revs
+        self._force_overwrite = False
--- a/mercurial/repair.py	Tue Sep 24 00:01:30 2024 +0200
+++ b/mercurial/repair.py	Mon Sep 23 23:52:45 2024 +0200
@@ -242,6 +242,10 @@
                 del repo.obsstore
                 repo.invalidatevolatilesets()
 
+            # NOTE: eventually make a common entry point on localrepo to help
+            # other caches
+            repo.revbranchcache().invalidate(striprev)
+
             if tmpbundlefile:
                 ui.note(_(b"adding branch\n"))
                 f = vfs.open(tmpbundlefile, b"rb")
--- a/tests/test-rebase-conflicts.t	Tue Sep 24 00:01:30 2024 +0200
+++ b/tests/test-rebase-conflicts.t	Mon Sep 23 23:52:45 2024 +0200
@@ -319,12 +319,14 @@
   bundle2-input-part: "phase-heads" supported
   bundle2-input-part: total payload size 24
   bundle2-input-bundle: 3 parts total
-  truncating cache/rbc-revs-v1 to 72
+  truncating cache/rbc-revs-v1 to 0
   added 2 changesets with 2 changes to 1 files
   updating the branch cache
   invalid branch cache (served): tip differs
+  history modification detected - truncating revision branch cache to revision 1
   invalid branch cache (served.hidden): tip differs
   rebase completed
+  truncating cache/rbc-revs-v1 to 8
 
 Test minimization of merge conflicts
   $ hg up -q null
--- a/tests/test-strip.t	Tue Sep 24 00:01:30 2024 +0200
+++ b/tests/test-strip.t	Mon Sep 23 23:52:45 2024 +0200
@@ -913,6 +913,7 @@
   saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/6625a5168474-345bb43d-backup.hg
   updating the branch cache
   invalid branch cache (served): tip differs
+  truncating cache/rbc-revs-v1 to 0
   $ hg log -G
   o  changeset:   2:5c51d8d6557d
   |  tag:         tip