Mercurial > public > mercurial-scm > hg-stable
diff mercurial/store.py @ 50657:e1ee6910f6bc
store: add a `get_revlog_instance` method on revlog entries
The upgrade code needs this a lot, and the stream code is about to needs it
too. So we start by moving the upgrade code in a more generic location.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 27 May 2023 04:01:17 +0200 |
parents | 0925eaf09c8b |
children | 3ea3767c23a4 |
line wrap: on
line diff
--- a/mercurial/store.py Mon May 29 02:22:20 2023 +0200 +++ b/mercurial/store.py Sat May 27 04:01:17 2023 +0200 @@ -19,6 +19,7 @@ from . import ( changelog, error, + filelog, manifest, policy, pycompat, @@ -545,6 +546,21 @@ files.append(StoreFile(unencoded_path=path, **data)) return files + def get_revlog_instance(self, repo): + """Obtain a revlog instance from this store entry + + An instance of the appropriate class is returned. + """ + if self.is_changelog: + return changelog.changelog(repo.svfs) + elif self.is_manifestlog: + mandir = self.target_id.rstrip(b'/') + return manifest.manifestrevlog( + repo.nodeconstants, repo.svfs, tree=mandir + ) + else: + return filelog.filelog(repo.svfs, self.target_id) + @attr.s(slots=True) class StoreFile: