changeset 50627: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 9b0fe2b075b5
children 3ea3767c23a4
files mercurial/store.py mercurial/upgrade_utils/engine.py
diffstat 2 files changed, 23 insertions(+), 26 deletions(-) [+]
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:
--- a/mercurial/upgrade_utils/engine.py	Mon May 29 02:22:20 2023 +0200
+++ b/mercurial/upgrade_utils/engine.py	Sat May 27 04:01:17 2023 +0200
@@ -11,10 +11,7 @@
 from ..i18n import _
 from ..pycompat import getattr
 from .. import (
-    changelog,
     error,
-    filelog,
-    manifest,
     metadata,
     pycompat,
     requirements,
@@ -47,22 +44,6 @@
     return sidedatamod.get_sidedata_helpers(srcrepo, dstrepo._wanted_sidedata)
 
 
-def _revlog_from_store_entry(repo, entry):
-    """Obtain a revlog from a repo store entry.
-
-    An instance of the appropriate class is returned.
-    """
-    if entry.is_changelog:
-        return changelog.changelog(repo.svfs)
-    elif entry.is_manifestlog:
-        mandir = entry.target_id.rstrip(b'/')
-        return manifest.manifestrevlog(
-            repo.nodeconstants, repo.svfs, tree=mandir
-        )
-    else:
-        return filelog.filelog(repo.svfs, entry.target_id)
-
-
 def _copyrevlog(tr, destrepo, oldrl, entry):
     """copy all relevant files for `oldrl` into `destrepo` store
 
@@ -71,7 +52,7 @@
     content is compatible with format of the destination repository.
     """
     oldrl = getattr(oldrl, '_revlog', oldrl)
-    newrl = _revlog_from_store_entry(destrepo, entry)
+    newrl = entry.get_revlog_instance(destrepo)
     newrl = getattr(newrl, '_revlog', newrl)
 
     oldvfs = oldrl.opener
@@ -138,7 +119,7 @@
             _(b'cloning %d revisions from %s\n')
             % (len(old_revlog), revlog_path)
         )
-        newrl = _revlog_from_store_entry(dstrepo, entry)
+        newrl = entry.get_revlog_instance(dstrepo)
         old_revlog.clone(
             tr,
             newrl,
@@ -152,7 +133,7 @@
         ui.note(msg % (revlog_path, len(old_revlog)))
         _copyrevlog(tr, dstrepo, old_revlog, entry)
 
-        newrl = _revlog_from_store_entry(dstrepo, entry)
+        newrl = entry.get_revlog_instance(dstrepo)
     return newrl
 
 
@@ -197,7 +178,7 @@
         if not entry.is_revlog:
             continue
 
-        rl = _revlog_from_store_entry(srcrepo, entry)
+        rl = entry.get_revlog_instance(srcrepo)
 
         info = rl.storageinfo(
             exclusivefiles=True,
@@ -272,7 +253,7 @@
     )
     progress = srcrepo.ui.makeprogress(_(b'file revisions'), total=frevcount)
     for target_id, entry in sorted(filelogs.items()):
-        oldrl = _revlog_from_store_entry(srcrepo, entry)
+        oldrl = entry.get_revlog_instance(srcrepo)
 
         newrl = _perform_clone(
             ui,
@@ -313,7 +294,7 @@
         _(b'manifest revisions'), total=mrevcount
     )
     for target_id, entry in sorted(manifests.items()):
-        oldrl = _revlog_from_store_entry(srcrepo, entry)
+        oldrl = entry.get_revlog_instance(srcrepo)
         newrl = _perform_clone(
             ui,
             dstrepo,
@@ -352,7 +333,7 @@
         _(b'changelog revisions'), total=crevcount
     )
     for target_id, entry in sorted(changelogs.items()):
-        oldrl = _revlog_from_store_entry(srcrepo, entry)
+        oldrl = entry.get_revlog_instance(srcrepo)
         newrl = _perform_clone(
             ui,
             dstrepo,