store: cache the file_size when we get it from disk
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 29 May 2023 04:24:29 +0200
changeset 50632 786443bd3bc1
parent 50631 b59e0a4f692f
child 50633 f2ae815ae34c
store: cache the file_size when we get it from disk The point of caching `files` is to ensure consistency and avoiding redoing expensive work. So we cache the file_size once retrieved.
mercurial/store.py
--- a/mercurial/store.py	Sun May 28 03:46:48 2023 +0200
+++ b/mercurial/store.py	Mon May 29 04:24:29 2023 +0200
@@ -578,12 +578,12 @@
     is_volatile = attr.ib(default=False)
 
     def file_size(self, vfs):
-        if self._file_size is not None:
-            return self._file_size
-        try:
-            return vfs.stat(self.unencoded_path).st_size
-        except FileNotFoundError:
-            return 0
+        if self._file_size is None:
+            try:
+                self._file_size = vfs.stat(self.unencoded_path).st_size
+            except FileNotFoundError:
+                self._file_size = 0
+        return self._file_size
 
 
 def _gather_revlog(files_data):