# HG changeset patch # User Pierre-Yves David # Date 1684133881 -7200 # Node ID 4cbdfab6f81240647a2708f3bd91f354d33c351e # Parent 2b2284cf949b3e81db4458419d615ac0a38462d5 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. diff -r 2b2284cf949b -r 4cbdfab6f812 mercurial/store.py --- 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 = ( diff -r 2b2284cf949b -r 4cbdfab6f812 mercurial/streamclone.py --- a/mercurial/streamclone.py Mon May 15 08:57:45 2023 +0200 +++ b/mercurial/streamclone.py Mon May 15 08:58:01 2023 +0200 @@ -271,9 +271,10 @@ repo.ui.debug(b'scanning\n') for entry in _walkstreamfiles(repo): for f in entry.files(): - if f.file_size: - entries.append((f.unencoded_path, f.file_size)) - total_bytes += f.file_size + file_size = f.file_size(repo.store.vfs) + if file_size: + entries.append((f.unencoded_path, file_size)) + total_bytes += file_size _test_sync_point_walk_1(repo) _test_sync_point_walk_2(repo) @@ -680,12 +681,13 @@ for entry in _walkstreamfiles(repo, matcher): for f in entry.files(): - if f.file_size: + file_size = f.file_size(repo.store.vfs) + if file_size: ft = _fileappend if f.is_volatile: ft = _filefull - entries.append((_srcstore, f.unencoded_path, ft, f.file_size)) - totalfilesize += f.file_size + entries.append((_srcstore, f.unencoded_path, ft, file_size)) + totalfilesize += file_size for name in _walkstreamfullstorefiles(repo): if repo.svfs.exists(name): totalfilesize += repo.svfs.lstat(name).st_size diff -r 2b2284cf949b -r 4cbdfab6f812 mercurial/verify.py --- a/mercurial/verify.py Mon May 15 08:57:45 2023 +0200 +++ b/mercurial/verify.py Mon May 15 08:58:01 2023 +0200 @@ -410,7 +410,7 @@ for entry in repo.store.datafiles(undecodable=undecodable): for file_ in entry.files(): f = file_.unencoded_path - size = file_.file_size + size = file_.file_size(repo.store.vfs) if (size > 0 or not revlogv1) and f.startswith(b'meta/'): storefiles.add(_normpath(f)) subdirs.add(os.path.dirname(f)) @@ -477,7 +477,7 @@ undecodable = [] for entry in repo.store.datafiles(undecodable=undecodable): for file_ in entry.files(): - size = file_.file_size + size = file_.file_size(repo.store.vfs) f = file_.unencoded_path if (size > 0 or not revlogv1) and f.startswith(b'data/'): storefiles.add(_normpath(f))