Patchwork D9578: upgrade: move printing of unused optimizations to UpgradeOperation class

login
register
mail settings
Submitter phabricator
Date Dec. 14, 2020, 9:55 a.m.
Message ID <differential-rev-PHID-DREV-j4nag7h5m5rpcz6k4fku-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47876/
State Superseded
Headers show

Comments

phabricator - Dec. 14, 2020, 9:55 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS




To: pulkit, #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
@@ -563,6 +563,7 @@ 
         new_requirements,
         current_requirements,
         actions,
+        all_optimizations,
         revlogs_to_process,
     ):
         self.ui = ui
@@ -583,6 +584,12 @@ 
         self.preserved_requirements = (
             self.current_requirements & self.new_requirements
         )
+        self.all_optimizations = all_optimizations
+        # optimizations which are not used and it's recommended that they
+        # should use them
+        self.unused_optimizations = [
+            i for i in all_optimizations if i not in self.actions
+        ]
 
     def _write_labeled(self, l, label):
         """
@@ -640,6 +647,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
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -128,6 +128,7 @@ 
         newreqs,
         repo.requirements,
         actions,
+        alloptimizations,
         revlogs,
     )
 
@@ -184,17 +185,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.