diff mercurial/branching/rev_cache.py @ 51940: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
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