branchcache: change the _delayed flag to an explicit `_dirty` flag
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 08 Mar 2024 16:47:32 +0100
changeset 51488 94f821490645
parent 51487 1a9bdd0e1c44
child 51489 659f766629c8
branchcache: change the _delayed flag to an explicit `_dirty` flag This is more consistent with the logic we use for other object and it open the way to a clearer management of the cache state. Now, cache are created clean, cache update mark them dirty, writing them on disk mark them clean again.
mercurial/branchmap.py
mercurial/localrepo.py
--- a/mercurial/branchmap.py	Fri Mar 08 15:50:15 2024 +0100
+++ b/mercurial/branchmap.py	Fri Mar 08 16:47:32 2024 +0100
@@ -74,7 +74,7 @@
         disk.
 
         If a transaction is in progress, the writing is schedule to transaction
-        close. See the `BranchMapCache.write_delayed` method.
+        close. See the `BranchMapCache.write_dirty` method.
 
         This method exist independently of __getitem__ as it is sometime useful
         to signal that we have no intend to use the data in memory yet.
@@ -164,13 +164,13 @@
     def clear(self):
         self._per_filter.clear()
 
-    def write_delayed(self, repo):
+    def write_dirty(self, repo):
         unfi = repo.unfiltered()
         for filtername in repoviewutil.get_ordered_subset():
             cache = self._per_filter.get(filtername)
             if cache is None:
                 continue
-            if cache._delayed:
+            if cache._dirty:
                 if filtername is None:
                     repo = unfi
                 else:
@@ -433,13 +433,13 @@
         has a given node or not. If it's not provided, we assume that every node
         we have exists in changelog"""
         self._filtername = repo.filtername
-        self._delayed = False
         if tipnode is None:
             self.tipnode = repo.nullid
         else:
             self.tipnode = tipnode
         self.tiprev = tiprev
         self.filteredhash = filteredhash
+        self._dirty = False
 
         super().__init__(repo=repo, entries=entries, closed_nodes=closednodes)
         # closednodes is a set of nodes that close their branch. If the branch
@@ -568,7 +568,7 @@
         )
         # we copy will likely schedule a write anyway, but that does not seems
         # to hurt to overschedule
-        other._delayed = self._delayed
+        other._dirty = self._dirty
         # also copy information about the current verification state
         other._verifiedbranches = set(self._verifiedbranches)
         return other
@@ -583,7 +583,6 @@
             # Avoid premature writing.
             #
             # (The cache warming setup by localrepo will update the file later.)
-            self._delayed = True
             return
         try:
             filename = self._filename(repo)
@@ -597,7 +596,7 @@
                 len(self._entries),
                 nodecount,
             )
-            self._delayed = False
+            self._dirty = False
         except (IOError, OSError, error.Abort) as inst:
             # Abort may be raised by read only opener, so log and continue
             repo.ui.debug(
@@ -707,7 +706,7 @@
         self.filteredhash = scmutil.filteredhash(
             repo, self.tiprev, needobsolete=True
         )
-
+        self._dirty = True
         self.write(repo)
 
 
--- a/mercurial/localrepo.py	Fri Mar 08 15:50:15 2024 +0100
+++ b/mercurial/localrepo.py	Fri Mar 08 16:47:32 2024 +0100
@@ -2974,7 +2974,7 @@
                 self._branchcaches.update_disk(filtered)
 
         # flush all possibly delayed write.
-        self._branchcaches.write_delayed(self)
+        self._branchcaches.write_dirty(self)
 
     def invalidatecaches(self):
         if '_tagscache' in vars(self):