diff mercurial/store.py @ 50477:4cbdfab6f812

store: lazily get file size on demand for the fncache case We don't have the information in the first place, so we can avoid querying the file system inconditionnaly for use case we don't needs it. This change requires the StoreFile class to be passed a vfs to retrieve the file_size if needed. In the non-fncache case, we already have the information from file system walking, so we keep it and use it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 15 May 2023 08:58:01 +0200
parents 2b2284cf949b
children 1c0244a8cdaf
line wrap: on
line diff
--- a/mercurial/store.py	Mon May 15 08:57:45 2023 +0200
+++ b/mercurial/store.py	Mon May 15 08:58:01 2023 +0200
@@ -520,9 +520,17 @@
     """a file matching an entry"""
 
     unencoded_path = attr.ib()
-    file_size = attr.ib()
+    _file_size = attr.ib(default=False)
     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
+
 
 class basicstore:
     '''base class for local repository stores'''
@@ -900,16 +908,12 @@
                 # However the fncache might contains such file added by
                 # previous version of Mercurial.
                 continue
-            try:
-                yield RevlogStoreEntry(
-                    unencoded_path=f,
-                    revlog_type=FILEFLAGS_FILELOG,
-                    is_revlog_main=bool(t & FILEFLAGS_REVLOG_MAIN),
-                    is_volatile=bool(t & FILEFLAGS_VOLATILE),
-                    file_size=self.getsize(ef),
-                )
-            except FileNotFoundError:
-                pass
+            yield RevlogStoreEntry(
+                unencoded_path=f,
+                revlog_type=FILEFLAGS_FILELOG,
+                is_revlog_main=bool(t & FILEFLAGS_REVLOG_MAIN),
+                is_volatile=bool(t & FILEFLAGS_VOLATILE),
+            )
 
     def copylist(self):
         d = (