upgrade: move `printupgradeactions()` to UpgradeOperation class
authorPulkit Goyal <7895pulkit@gmail.com>
Sat, 12 Dec 2020 17:54:59 +0530
changeset 46189 dfddcbb0c244
parent 46188 945b33a7edfd
child 46190 9ab2ab5bf9af
upgrade: move `printupgradeactions()` to UpgradeOperation class Part of refactor where we make things more arranged and integrated into single `UpgradeOperation` class. Differential Revision: https://phab.mercurial-scm.org/D9575
mercurial/upgrade.py
mercurial/upgrade_utils/actions.py
mercurial/upgrade_utils/engine.py
--- a/mercurial/upgrade.py	Sat Dec 12 17:51:27 2020 +0530
+++ b/mercurial/upgrade.py	Sat Dec 12 17:54:59 2020 +0530
@@ -163,14 +163,10 @@
             )
             ui.write(b'\n\n')
 
-    def printupgradeactions():
-        for a in actions:
-            ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))
-
     upgrade_op = upgrade_actions.UpgradeOperation(
         ui,
         newreqs,
-        [a.name for a in actions],
+        actions,
         revlogs,
     )
 
@@ -224,7 +220,7 @@
 
         printrequirements()
         printoptimisations()
-        printupgradeactions()
+        upgrade_op.print_upgrade_actions()
         upgrade_op.print_affected_revlogs()
 
         unusedoptimize = [i for i in alloptimizations if i not in actions]
@@ -244,7 +240,7 @@
     ui.write(_(b'upgrade will perform the following actions:\n\n'))
     printrequirements()
     printoptimisations()
-    printupgradeactions()
+    upgrade_op.print_upgrade_actions()
     upgrade_op.print_affected_revlogs()
 
     ui.status(_(b'beginning upgrade...\n'))
--- a/mercurial/upgrade_utils/actions.py	Sat Dec 12 17:51:27 2020 +0530
+++ b/mercurial/upgrade_utils/actions.py	Sat Dec 12 17:54:59 2020 +0530
@@ -561,8 +561,13 @@
         self.ui = ui
         self.requirements = requirements
         self.actions = actions
+        self._actions_names = set([a.name for a in actions])
         self.revlogs_to_process = revlogs_to_process
 
+    def print_upgrade_actions(self):
+        for a in self.actions:
+            self.ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))
+
     def print_affected_revlogs(self):
         if not self.revlogs_to_process:
             self.ui.write((b'no revlogs to process\n'))
@@ -572,6 +577,10 @@
                 self.ui.write((b'  - %s\n' % r))
         self.ui.write((b'\n'))
 
+    def has_action(self, name):
+        """ Check whether the upgrade operation will perform this action """
+        return name in self._actions_names
+
 
 ###  Code checking if a repository can got through the upgrade process at all. #
 
--- a/mercurial/upgrade_utils/engine.py	Sat Dec 12 17:51:27 2020 +0530
+++ b/mercurial/upgrade_utils/engine.py	Sat Dec 12 17:54:59 2020 +0530
@@ -403,13 +403,13 @@
         )
     )
 
-    if b're-delta-all' in upgrade_op.actions:
+    if upgrade_op.has_action(b're-delta-all'):
         deltareuse = revlog.revlog.DELTAREUSENEVER
-    elif b're-delta-parent' in upgrade_op.actions:
+    elif upgrade_op.has_action(b're-delta-parent'):
         deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-    elif b're-delta-multibase' in upgrade_op.actions:
+    elif upgrade_op.has_action(b're-delta-multibase'):
         deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-    elif b're-delta-fulladd' in upgrade_op.actions:
+    elif upgrade_op.has_action(b're-delta-fulladd'):
         deltareuse = revlog.revlog.DELTAREUSEFULLADD
     else:
         deltareuse = revlog.revlog.DELTAREUSEALWAYS
@@ -421,7 +421,7 @@
             dstrepo,
             tr,
             deltareuse,
-            b're-delta-multibase' in upgrade_op.actions,
+            upgrade_op.has_action(b're-delta-multibase'),
             revlogs=upgrade_op.revlogs_to_process,
         )