changeset 50632:786443bd3bc1

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 29 May 2023 04:24:29 +0200
parents b59e0a4f692f
children f2ae815ae34c
files mercurial/store.py
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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):