branchcache: explictly update disk state only if no transaction exist
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 10 Mar 2024 03:25:04 +0100
changeset 51495 0c684ca692a4
parent 51494 54f0dd798346
child 51496 79a7616a82b8
branchcache: explictly update disk state only if no transaction exist If a transaction exist the `write_dirty` call will eventually be done and the state will be synched on disk. It is better to no interfer with that.
mercurial/branchmap.py
--- a/mercurial/branchmap.py	Sun Mar 10 03:32:50 2024 +0100
+++ b/mercurial/branchmap.py	Sun Mar 10 03:25:04 2024 +0100
@@ -85,7 +85,9 @@
             bcache._filtername,
             repo.filtername,
         )
-        bcache.sync_disk(repo)
+        tr = repo.currenttransaction()
+        if getattr(tr, 'finalized', True):
+            bcache.sync_disk(repo)
 
     def updatecache(self, repo):
         """Update the cache for the given filtered view on a repository"""
@@ -603,12 +605,11 @@
             repo.filtername,
         )
         assert self._state == STATE_DIRTY, self._state
+        # This method should not be called during an open transaction
         tr = repo.currenttransaction()
         if not getattr(tr, 'finalized', True):
-            # Avoid premature writing.
-            #
-            # (The cache warming setup by localrepo will update the file later.)
-            return
+            msg = "writing branchcache in the middle of a transaction"
+            raise error.ProgrammingError(msg)
         try:
             filename = self._filename(repo)
             with repo.cachevfs(filename, b"w", atomictemp=True) as f:
@@ -732,7 +733,12 @@
             repo, self.tiprev, needobsolete=True
         )
         self._state = STATE_DIRTY
-        self.write(repo)
+        tr = repo.currenttransaction()
+        if getattr(tr, 'finalized', True):
+            # Avoid premature writing.
+            #
+            # (The cache warming setup by localrepo will update the file later.)
+            self.write(repo)
 
 
 class remotebranchcache(_BaseBranchCache):