upgrade: move `printoptimisations() to UpgradeOperation class
authorPulkit Goyal <7895pulkit@gmail.com>
Sat, 12 Dec 2020 18:00:18 +0530
changeset 46190 9ab2ab5bf9af
parent 46189 dfddcbb0c244
child 46191 aba979b1b90b
upgrade: move `printoptimisations() 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/D9576
mercurial/upgrade.py
mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade.py	Sat Dec 12 17:54:59 2020 +0530
+++ b/mercurial/upgrade.py	Sat Dec 12 18:00:18 2020 +0530
@@ -150,19 +150,6 @@
             ui.write((b'\n'))
         ui.write(b'\n')
 
-    def printoptimisations():
-        optimisations = [
-            a for a in actions if a.type == upgrade_actions.OPTIMISATION
-        ]
-        optimisations.sort(key=lambda a: a.name)
-        if optimisations:
-            ui.write(_(b'optimisations: '))
-            write_labeled(
-                [a.name for a in optimisations],
-                "upgrade-repo.optimisation.performed",
-            )
-            ui.write(b'\n\n')
-
     upgrade_op = upgrade_actions.UpgradeOperation(
         ui,
         newreqs,
@@ -219,7 +206,7 @@
         )
 
         printrequirements()
-        printoptimisations()
+        upgrade_op.print_optimisations()
         upgrade_op.print_upgrade_actions()
         upgrade_op.print_affected_revlogs()
 
@@ -239,7 +226,7 @@
     # Else we're in the run=true case.
     ui.write(_(b'upgrade will perform the following actions:\n\n'))
     printrequirements()
-    printoptimisations()
+    upgrade_op.print_optimisations()
     upgrade_op.print_upgrade_actions()
     upgrade_op.print_affected_revlogs()
 
--- a/mercurial/upgrade_utils/actions.py	Sat Dec 12 17:54:59 2020 +0530
+++ b/mercurial/upgrade_utils/actions.py	Sat Dec 12 18:00:18 2020 +0530
@@ -564,6 +564,28 @@
         self._actions_names = set([a.name for a in actions])
         self.revlogs_to_process = revlogs_to_process
 
+    def _write_labeled(self, l, label):
+        """
+        Utility function to aid writing of a list under one label
+        """
+        first = True
+        for r in sorted(l):
+            if not first:
+                self.ui.write(b', ')
+            self.ui.write(r, label=label)
+            first = False
+
+    def print_optimisations(self):
+        optimisations = [a for a in self.actions if a.type == OPTIMISATION]
+        optimisations.sort(key=lambda a: a.name)
+        if optimisations:
+            self.ui.write(_(b'optimisations: '))
+            self._write_labeled(
+                [a.name for a in optimisations],
+                "upgrade-repo.optimisation.performed",
+            )
+            self.ui.write(b'\n\n')
+
     def print_upgrade_actions(self):
         for a in self.actions:
             self.ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))