# HG changeset patch # User Raphaël Gomès # Date 1722278046 -7200 # Node ID ba9df4e6abb8579f4c8590ceaa7609453392abf7 # Parent 067ec8574c339b6ba720dc10b8a3a6587dfb6e91 fncache: refactor load check into a property This makes the intent more obvious new callers less prone to error. diff -r 067ec8574c33 -r ba9df4e6abb8 mercurial/store.py --- 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.