Patchwork D9576: upgrade: move `printoptimisations() to UpgradeOperation class

login
register
mail settings
Submitter phabricator
Date Dec. 14, 2020, 9:55 a.m.
Message ID <differential-rev-PHID-DREV-d4644xlgg2jjnexd6nlc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47874/
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.

REVISION SUMMARY
  Part of refactor where we make things more arranged and integrated into single
  `UpgradeOperation` class.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -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))
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -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()