Patchwork D12612: upgrade: split some logic from UpgradeOperation

login
register
mail settings
Submitter phabricator
Date May 6, 2022, 8:37 a.m.
Message ID <differential-rev-PHID-DREV-s55qxl7w2h3wvrqf57iz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50963/
State New
Headers show

Comments

phabricator - May 6, 2022, 8:37 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The automatic-upgrade and the upgrade-repo code path 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 changesets.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12612

AFFECTED FILES
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/upgrade_utils/actions.py b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -685,7 +685,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__(
@@ -698,8 +715,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
@@ -741,9 +761,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])