upgrade: split some logic from UpgradeOperation
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 04 Apr 2022 19:30:32 +0200
changeset 49193 566066826e7c
parent 49192 2ab79873786e
child 49194 e4b31016e194
upgrade: split some logic from UpgradeOperation The logic for automatic-upgrade and the upgrade-repo should be able to use the same code. However that code often need an UpgradeOperation object to function. So we start spliting the Operation into a minimal component that we will be able to reuse outside of the "classic" upgrade path. We will put the base-class to use in the next changeset. Differential Revision: https://phab.mercurial-scm.org/D12612
mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py	Tue Apr 05 05:19:47 2022 +0200
+++ b/mercurial/upgrade_utils/actions.py	Mon Apr 04 19:30:32 2022 +0200
@@ -691,7 +691,24 @@
     return newactions
 
 
-class UpgradeOperation:
+class BaseOperation:
+    """base class that contains the minimum for an upgrade to work
+
+    (this might need to be extended as the usage for subclass alternative to
+    UpgradeOperation extends)
+    """
+
+    def __init__(
+        self,
+        new_requirements,
+        backup_store,
+    ):
+        self.new_requirements = new_requirements
+        # should this operation create a backup of the store
+        self.backup_store = backup_store
+
+
+class UpgradeOperation(BaseOperation):
     """represent the work to be done during an upgrade"""
 
     def __init__(
@@ -704,8 +721,11 @@
         revlogs_to_process,
         backup_store,
     ):
+        super().__init__(
+            new_requirements,
+            backup_store,
+        )
         self.ui = ui
-        self.new_requirements = new_requirements
         self.current_requirements = current_requirements
         # list of upgrade actions the operation will perform
         self.upgrade_actions = upgrade_actions
@@ -747,9 +767,6 @@
             b're-delta-multibase' in upgrade_actions_names
         )
 
-        # should this operation create a backup of the store
-        self.backup_store = backup_store
-
     @property
     def upgrade_actions_names(self):
         return set([a.name for a in self.upgrade_actions])