# HG changeset patch # User Pierre-Yves David # Date 1684133816 -7200 # Node ID 5a2fb64d38b2386e42eeeac753eb22107d44b623 # Parent 9fdc28e21b6886abf8900dee47ceecbc8781700f store: use specialized class for store entries We introduce two different classes for revlog and other entries. For now, we still have multiple entry for the same revlog, but we will work toward grouping the different file in a single entry in this series. Having the distinction is a step toward this goal. diff -r 9fdc28e21b68 -r 5a2fb64d38b2 hgext/remotefilelog/remotefilelogserver.py --- a/hgext/remotefilelog/remotefilelogserver.py Mon May 15 08:56:40 2023 +0200 +++ b/hgext/remotefilelog/remotefilelogserver.py Mon May 15 08:56:56 2023 +0200 @@ -162,11 +162,8 @@ ): n = util.pconvert(fp[striplen:]) d = store.decodedir(n) - yield store.StoreEntry( + yield store.SimpleStoreEntry( unencoded_path=d, - is_revlog=True, - revlog_type=None, - is_revlog_main=False, is_volatile=False, file_size=st.st_size, ) diff -r 9fdc28e21b68 -r 5a2fb64d38b2 mercurial/store.py --- a/mercurial/store.py Mon May 15 08:56:40 2023 +0200 +++ b/mercurial/store.py Mon May 15 08:56:56 2023 +0200 @@ -454,15 +454,12 @@ @attr.s(slots=True) -class StoreEntry: +class BaseStoreEntry: """An entry in the store This is returned by `store.walk` and represent some data in the store.""" unencoded_path = attr.ib() - is_revlog = attr.ib(default=False) - revlog_type = attr.ib(default=None) - is_revlog_main = attr.ib(default=None) is_volatile = attr.ib(default=False) file_size = attr.ib(default=None) @@ -477,6 +474,22 @@ @attr.s(slots=True) +class SimpleStoreEntry(BaseStoreEntry): + """A generic entry in the store""" + + is_revlog = False + + +@attr.s(slots=True) +class RevlogStoreEntry(BaseStoreEntry): + """A revlog entry in the store""" + + is_revlog = True + revlog_type = attr.ib(default=None) + is_revlog_main = attr.ib(default=None) + + +@attr.s(slots=True) class StoreFile: """a file matching an entry""" @@ -536,7 +549,7 @@ def datafiles( self, matcher=None, undecodable=None - ) -> Generator[StoreEntry, None, None]: + ) -> Generator[BaseStoreEntry, None, None]: """Like walk, but excluding the changelog and root manifest. When [undecodable] is None, revlogs names that can't be @@ -546,35 +559,42 @@ files = self._walk(b'data', True) + self._walk(b'meta', True) for (t, u, s) in files: if t is not None: - yield StoreEntry( + yield RevlogStoreEntry( unencoded_path=u, - is_revlog=True, revlog_type=FILEFLAGS_FILELOG, is_revlog_main=bool(t & FILEFLAGS_REVLOG_MAIN), is_volatile=bool(t & FILEFLAGS_VOLATILE), file_size=s, ) - def topfiles(self) -> Generator[StoreEntry, None, None]: + def topfiles(self) -> Generator[BaseStoreEntry, None, None]: # yield manifest before changelog files = reversed(self._walk(b'', False)) for (t, u, s) in files: if u.startswith(b'00changelog'): - revlog_type = FILEFLAGS_CHANGELOG + yield RevlogStoreEntry( + unencoded_path=u, + revlog_type=FILEFLAGS_CHANGELOG, + is_revlog_main=bool(t & FILEFLAGS_REVLOG_MAIN), + is_volatile=bool(t & FILEFLAGS_VOLATILE), + file_size=s, + ) elif u.startswith(b'00manifest'): - revlog_type = FILEFLAGS_MANIFESTLOG + yield RevlogStoreEntry( + unencoded_path=u, + revlog_type=FILEFLAGS_MANIFESTLOG, + is_revlog_main=bool(t & FILEFLAGS_REVLOG_MAIN), + is_volatile=bool(t & FILEFLAGS_VOLATILE), + file_size=s, + ) else: - revlog_type = None - yield StoreEntry( - unencoded_path=u, - is_revlog=revlog_type is not None, - revlog_type=revlog_type, - is_revlog_main=bool(t & FILEFLAGS_REVLOG_MAIN), - is_volatile=bool(t & FILEFLAGS_VOLATILE), - file_size=s, - ) + yield SimpleStoreEntry( + unencoded_path=u, + is_volatile=bool(t & FILEFLAGS_VOLATILE), + file_size=s, + ) - def walk(self, matcher=None) -> Generator[StoreEntry, None, None]: + def walk(self, matcher=None) -> Generator[BaseStoreEntry, None, None]: """return files related to data storage (ie: revlogs) yields (file_type, unencoded, size) @@ -629,7 +649,7 @@ def datafiles( self, matcher=None, undecodable=None - ) -> Generator[StoreEntry, None, None]: + ) -> Generator[BaseStoreEntry, None, None]: for entry in super(encodedstore, self).datafiles(): try: f1 = entry.unencoded_path @@ -842,7 +862,7 @@ def datafiles( self, matcher=None, undecodable=None - ) -> Generator[StoreEntry, None, None]: + ) -> Generator[BaseStoreEntry, None, None]: for f in sorted(self.fncache): if not _matchtrackedpath(f, matcher): continue @@ -854,11 +874,9 @@ # However the fncache might contains such file added by # previous version of Mercurial. continue - t |= FILEFLAGS_FILELOG try: - yield StoreEntry( + yield RevlogStoreEntry( unencoded_path=f, - is_revlog=True, revlog_type=FILEFLAGS_FILELOG, is_revlog_main=bool(t & FILEFLAGS_REVLOG_MAIN), is_volatile=bool(t & FILEFLAGS_VOLATILE),