# HG changeset patch # User Pierre-Yves David # Date 2023-05-15 06:56:40 # Node ID 9fdc28e21b6886abf8900dee47ceecbc8781700f # Parent 521fec115dad90b3142c70863c2671859a895a23 store: introduce a EntryFile object to actually access file info For now a StoreEntry match a single file, but the goal is to eventually combine multiple file in a higher level Entry, so we need to introduce this distinction and use it first. diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py --- a/hgext/narrow/narrowcommands.py +++ b/hgext/narrow/narrowcommands.py @@ -293,7 +293,8 @@ def _narrow( if f.startswith(b'data/'): file = f[5:-2] if not newmatch(file): - todelete.append(f) + for file_ in entry.files(): + todelete.append(file_.unencoded_path) elif f.startswith(b'meta/'): dir = f[5:-13] dirs = sorted(pathutil.dirs({dir})) + [dir] @@ -306,7 +307,8 @@ def _narrow( if visit == b'all': break if not include: - todelete.append(f) + for file_ in entry.files(): + todelete.append(file_.unencoded_path) repo.destroying() diff --git a/mercurial/store.py b/mercurial/store.py --- a/mercurial/store.py +++ b/mercurial/store.py @@ -466,6 +466,24 @@ class StoreEntry: is_volatile = attr.ib(default=False) file_size = attr.ib(default=None) + def files(self): + return [ + StoreFile( + unencoded_path=self.unencoded_path, + file_size=self.file_size, + is_volatile=self.is_volatile, + ) + ] + + +@attr.s(slots=True) +class StoreFile: + """a file matching an entry""" + + unencoded_path = attr.ib() + file_size = attr.ib() + is_volatile = attr.ib(default=False) + class basicstore: '''base class for local repository stores''' diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py --- a/mercurial/streamclone.py +++ b/mercurial/streamclone.py @@ -270,9 +270,10 @@ def generatev1(repo): with repo.lock(): repo.ui.debug(b'scanning\n') for entry in _walkstreamfiles(repo): - if entry.file_size: - entries.append((entry.unencoded_path, entry.file_size)) - total_bytes += entry.file_size + for f in entry.files(): + if f.file_size: + entries.append((f.unencoded_path, f.file_size)) + total_bytes += f.file_size _test_sync_point_walk_1(repo) _test_sync_point_walk_2(repo) @@ -678,14 +679,13 @@ def _v2_walk(repo, includes, excludes, i matcher = narrowspec.match(repo.root, includes, excludes) for entry in _walkstreamfiles(repo, matcher): - if entry.file_size: - ft = _fileappend - if entry.is_volatile: - ft = _filefull - entries.append( - (_srcstore, entry.unencoded_path, ft, entry.file_size) - ) - totalfilesize += entry.file_size + for f in entry.files(): + if f.file_size: + ft = _fileappend + if f.is_volatile: + ft = _filefull + entries.append((_srcstore, f.unencoded_path, ft, f.file_size)) + totalfilesize += f.file_size for name in _walkstreamfullstorefiles(repo): if repo.svfs.exists(name): totalfilesize += repo.svfs.lstat(name).st_size diff --git a/mercurial/verify.py b/mercurial/verify.py --- a/mercurial/verify.py +++ b/mercurial/verify.py @@ -408,11 +408,12 @@ class verifier: revlogv1 = self.revlogv1 undecodable = [] for entry in repo.store.datafiles(undecodable=undecodable): - f = entry.unencoded_path - size = entry.file_size - if (size > 0 or not revlogv1) and f.startswith(b'meta/'): - storefiles.add(_normpath(f)) - subdirs.add(os.path.dirname(f)) + for file_ in entry.files(): + f = file_.unencoded_path + size = file_.file_size + if (size > 0 or not revlogv1) and f.startswith(b'meta/'): + storefiles.add(_normpath(f)) + subdirs.add(os.path.dirname(f)) for f in undecodable: self._err(None, _(b"cannot decode filename '%s'") % f) subdirprogress = ui.makeprogress( @@ -475,10 +476,11 @@ class verifier: storefiles = set() undecodable = [] for entry in repo.store.datafiles(undecodable=undecodable): - size = entry.file_size - f = entry.unencoded_path - if (size > 0 or not revlogv1) and f.startswith(b'data/'): - storefiles.add(_normpath(f)) + for file_ in entry.files(): + size = file_.file_size + f = file_.unencoded_path + if (size > 0 or not revlogv1) and f.startswith(b'data/'): + storefiles.add(_normpath(f)) for f in undecodable: self._err(None, _(b"cannot decode filename '%s'") % f)