Patchwork D9575: upgrade: move `printupgradeactions()` to UpgradeOperation class

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

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

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/upgrade_utils/engine.py b/mercurial/upgrade_utils/engine.py
--- a/mercurial/upgrade_utils/engine.py
+++ b/mercurial/upgrade_utils/engine.py
@@ -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,
         )
 
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
@@ -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. #
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -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'))