changeset 52173:ba9df4e6abb8

fncache: refactor load check into a property This makes the intent more obvious new callers less prone to error.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 29 Jul 2024 20:34:06 +0200
parents 067ec8574c33
children 9fbdf355c916
files mercurial/store.py
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/store.py	Mon Jul 29 20:49:07 2024 +0200
+++ b/mercurial/store.py	Mon Jul 29 20:34:06 2024 +0200
@@ -998,12 +998,16 @@
         # set of new additions to fncache
         self.addls = set()
 
+    @property
+    def is_loaded(self):
+        return self.entries is not None
+
     def ensureloaded(self, warn=None):
         """read the fncache file if not already read.
 
         If the file on disk is corrupted, raise. If warn is provided,
         warn and keep going instead."""
-        if self.entries is None:
+        if not self.is_loaded:
             self._load(warn)
 
     def _load(self, warn=None):
@@ -1058,7 +1062,7 @@
 
     def write(self, tr):
         if self._dirty:
-            assert self.entries is not None
+            assert self.is_loaded
             self.entries = self.entries | self.addls
             self.addls = set()
             tr.addbackup(b'fncache')
@@ -1083,13 +1087,13 @@
     def add(self, fn):
         if fn in self._ignores:
             return
-        if self.entries is None:
+        if not self.is_loaded:
             self._load()
         if fn not in self.entries:
             self.addls.add(fn)
 
     def remove(self, fn):
-        if self.entries is None:
+        if not self.is_loaded:
             self._load()
         if fn in self.addls:
             self.addls.remove(fn)
@@ -1103,12 +1107,12 @@
     def __contains__(self, fn):
         if fn in self.addls:
             return True
-        if self.entries is None:
+        if not self.is_loaded:
             self._load()
         return fn in self.entries
 
     def __iter__(self):
-        if self.entries is None:
+        if not self.is_loaded:
             self._load()
         return iter(self.entries | self.addls)
 
@@ -1128,7 +1132,7 @@
         ):
             # do not trigger a fncache load when adding a file that already is
             # known to exist.
-            notload = self.fncache.entries is None and (
+            notload = not self.fncache.is_loaded and (
                 # if the file has size zero, it should be considered as missing.
                 # Such zero-size files are the result of truncation when a
                 # transaction is aborted.