upgrade: move printing of unused optimizations to UpgradeOperation class
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 14 Dec 2020 13:48:25 +0530
changeset 46192 25d11b24dedf
parent 46191 aba979b1b90b
child 46193 85f7cf314b39
upgrade: move printing of unused optimizations to UpgradeOperation class Differential Revision: https://phab.mercurial-scm.org/D9578
mercurial/upgrade.py
mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade.py	Sat Dec 12 18:09:16 2020 +0530
+++ b/mercurial/upgrade.py	Mon Dec 14 13:48:25 2020 +0530
@@ -184,17 +184,14 @@
         upgrade_op.print_upgrade_actions()
         upgrade_op.print_affected_revlogs()
 
-        unusedoptimize = [i for i in alloptimizations if i not in actions]
-
-        if unusedoptimize:
+        if upgrade_op.unused_optimizations:
             ui.status(
                 _(
                     b'additional optimizations are available by specifying '
                     b'"--optimize <name>":\n\n'
                 )
             )
-            for i in unusedoptimize:
-                ui.status(_(b'%s\n   %s\n\n') % (i.name, i.description))
+            upgrade_op.print_unused_optimizations()
         return
 
     # Else we're in the run=true case.
--- a/mercurial/upgrade_utils/actions.py	Sat Dec 12 18:09:16 2020 +0530
+++ b/mercurial/upgrade_utils/actions.py	Mon Dec 14 13:48:25 2020 +0530
@@ -583,6 +583,12 @@
         self._preserved_requirements = (
             self.current_requirements & self.new_requirements
         )
+        # optimizations which are not used and it's recommended that they
+        # should use them
+        all_optimizations = findoptimizations(None)
+        self.unused_optimizations = [
+            i for i in all_optimizations if i not in self.actions
+        ]
 
     def _write_labeled(self, l, label):
         """
@@ -640,6 +646,10 @@
                 self.ui.write((b'  - %s\n' % r))
         self.ui.write((b'\n'))
 
+    def print_unused_optimizations(self):
+        for i in self.unused_optimizations:
+            self.ui.status(_(b'%s\n   %s\n\n') % (i.name, i.description))
+
     def has_action(self, name):
         """ Check whether the upgrade operation will perform this action """
         return name in self._actions_names