mercurial/upgrade_utils/actions.py
changeset 46705 fd55a9eb1507
parent 46638 b4c2a2af25e2
child 46706 7d9d9265d40f
--- a/mercurial/upgrade_utils/actions.py	Thu Jan 28 15:28:57 2021 +0100
+++ b/mercurial/upgrade_utils/actions.py	Wed Jan 20 21:14:06 2021 +0100
@@ -328,7 +328,7 @@
 class sidedata(requirementformatvariant):
     name = b'sidedata'
 
-    _requirement = requirements.SIDEDATA_REQUIREMENT
+    _requirement = requirements.REVLOGV2_REQUIREMENT
 
     default = False
 
@@ -339,6 +339,11 @@
 
     upgrademessage = _(b'Allows storage of extra data alongside a revision.')
 
+    @classmethod
+    def fromrepo(cls, repo):
+        assert cls._requirement is not None
+        return cls._requirement in repo.requirements
+
 
 @registerformatvariant
 class persistentnodemap(requirementformatvariant):
@@ -371,6 +376,15 @@
 
 
 @registerformatvariant
+class revlogv2(requirementformatvariant):
+    name = b'revlog-v2'
+    _requirement = requirements.REVLOGV2_REQUIREMENT
+    default = False
+    description = _(b'Version 2 of the revlog.')
+    upgrademessage = _(b'very experimental')
+
+
+@registerformatvariant
 class removecldeltachain(formatvariant):
     name = b'plain-cl-delta'
 
@@ -857,8 +871,6 @@
     """
     return {
         # Introduced in Mercurial 0.9.2.
-        requirements.REVLOGV1_REQUIREMENT,
-        # Introduced in Mercurial 0.9.2.
         requirements.STORE_REQUIREMENT,
     }
 
@@ -881,9 +893,21 @@
     }
 
 
+def check_revlog_version(reqs):
+    """Check that the requirements contain at least one Revlog version"""
+    all_revlogs = {
+        requirements.REVLOGV1_REQUIREMENT,
+        requirements.REVLOGV2_REQUIREMENT,
+    }
+    if not all_revlogs.intersection(reqs):
+        msg = _(b'cannot upgrade repository; missing a revlog version')
+        raise error.Abort(msg)
+
+
 def check_source_requirements(repo):
     """Ensure that no existing requirements prevent the repository upgrade"""
 
+    check_revlog_version(repo.requirements)
     required = requiredsourcerequirements(repo)
     missingreqs = required - repo.requirements
     if missingreqs:
@@ -915,6 +939,8 @@
         requirements.COPIESSDC_REQUIREMENT,
         requirements.NODEMAP_REQUIREMENT,
         requirements.SHARESAFE_REQUIREMENT,
+        requirements.REVLOGV2_REQUIREMENT,
+        requirements.REVLOGV1_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -937,13 +963,14 @@
         requirements.DOTENCODE_REQUIREMENT,
         requirements.FNCACHE_REQUIREMENT,
         requirements.GENERALDELTA_REQUIREMENT,
-        requirements.REVLOGV1_REQUIREMENT,
+        requirements.REVLOGV1_REQUIREMENT,  # allowed in case of downgrade
         requirements.STORE_REQUIREMENT,
         requirements.SPARSEREVLOG_REQUIREMENT,
         requirements.SIDEDATA_REQUIREMENT,
         requirements.COPIESSDC_REQUIREMENT,
         requirements.NODEMAP_REQUIREMENT,
         requirements.SHARESAFE_REQUIREMENT,
+        requirements.REVLOGV2_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -973,6 +1000,8 @@
         requirements.COPIESSDC_REQUIREMENT,
         requirements.NODEMAP_REQUIREMENT,
         requirements.SHARESAFE_REQUIREMENT,
+        requirements.REVLOGV1_REQUIREMENT,
+        requirements.REVLOGV2_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -985,7 +1014,7 @@
 
 def check_requirements_changes(repo, new_reqs):
     old_reqs = repo.requirements
-
+    check_revlog_version(repo.requirements)
     support_removal = supportremovedrequirements(repo)
     no_remove_reqs = old_reqs - new_reqs - support_removal
     if no_remove_reqs: