Patchwork D9577: upgrade: move `printrequirements()` to UpgradeOperation class

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

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
@@ -429,7 +429,7 @@ 
     # The sorted() makes execution deterministic.
     for p, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)):
         if not _filterstorefile(
-            srcrepo, dstrepo, upgrade_op.requirements, p, kind, st
+            srcrepo, dstrepo, upgrade_op.new_requirements, p, kind, st
         ):
             continue
 
@@ -489,7 +489,7 @@ 
             b'again\n'
         )
     )
-    scmutil.writereporequirements(srcrepo, upgrade_op.requirements)
+    scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
 
     # The lock file from the old store won't be removed because nothing has a
     # reference to its new location. So clean it up manually. Alternatively, we
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
@@ -557,12 +557,32 @@ 
 class UpgradeOperation(object):
     """represent the work to be done during an upgrade"""
 
-    def __init__(self, ui, requirements, actions, revlogs_to_process):
+    def __init__(
+        self,
+        ui,
+        new_requirements,
+        current_requirements,
+        actions,
+        revlogs_to_process,
+    ):
         self.ui = ui
-        self.requirements = requirements
+        self.new_requirements = new_requirements
+        self.current_requirements = current_requirements
         self.actions = actions
         self._actions_names = set([a.name for a in actions])
         self.revlogs_to_process = revlogs_to_process
+        # requirements which will be added by the operation
+        self.added_requirements = (
+            self.new_requirements - self.current_requirements
+        )
+        # requirements which will be removed by the operation
+        self.removed_requirements = (
+            self.current_requirements - self.new_requirements
+        )
+        # requirements which will be preserved by the operation
+        self.preserved_requirements = (
+            self.current_requirements & self.new_requirements
+        )
 
     def _write_labeled(self, l, label):
         """
@@ -575,6 +595,27 @@ 
             self.ui.write(r, label=label)
             first = False
 
+    def print_requirements(self):
+        self.ui.write(_(b'requirements\n'))
+        self.ui.write(_(b'   preserved: '))
+        self._write_labeled(
+            self.preserved_requirements, "upgrade-repo.requirement.preserved"
+        )
+        self.ui.write((b'\n'))
+        if self.removed_requirements:
+            self.ui.write(_(b'   removed: '))
+            self._write_labeled(
+                self.removed_requirements, "upgrade-repo.requirement.removed"
+            )
+            self.ui.write((b'\n'))
+        if self.added_requirements:
+            self.ui.write(_(b'   added: '))
+            self._write_labeled(
+                self.added_requirements, "upgrade-repo.requirement.added"
+            )
+            self.ui.write((b'\n'))
+        self.ui.write(b'\n')
+
     def print_optimisations(self):
         optimisations = [a for a in self.actions if a.type == OPTIMISATION]
         optimisations.sort(key=lambda a: a.name)
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -123,36 +123,10 @@ 
             ui.warn(msg % b', '.join(sorted(incompatible)))
             revlogs = upgrade_engine.UPGRADE_ALL_REVLOGS
 
-    def write_labeled(l, label):
-        first = True
-        for r in sorted(l):
-            if not first:
-                ui.write(b', ')
-            ui.write(r, label=label)
-            first = False
-
-    def printrequirements():
-        ui.write(_(b'requirements\n'))
-        ui.write(_(b'   preserved: '))
-        write_labeled(
-            newreqs & repo.requirements, "upgrade-repo.requirement.preserved"
-        )
-        ui.write((b'\n'))
-        removed = repo.requirements - newreqs
-        if repo.requirements - newreqs:
-            ui.write(_(b'   removed: '))
-            write_labeled(removed, "upgrade-repo.requirement.removed")
-            ui.write((b'\n'))
-        added = newreqs - repo.requirements
-        if added:
-            ui.write(_(b'   added: '))
-            write_labeled(added, "upgrade-repo.requirement.added")
-            ui.write((b'\n'))
-        ui.write(b'\n')
-
     upgrade_op = upgrade_actions.UpgradeOperation(
         ui,
         newreqs,
+        repo.requirements,
         actions,
         revlogs,
     )
@@ -205,7 +179,7 @@ 
             )
         )
 
-        printrequirements()
+        upgrade_op.print_requirements()
         upgrade_op.print_optimisations()
         upgrade_op.print_upgrade_actions()
         upgrade_op.print_affected_revlogs()
@@ -225,7 +199,7 @@ 
 
     # Else we're in the run=true case.
     ui.write(_(b'upgrade will perform the following actions:\n\n'))
-    printrequirements()
+    upgrade_op.print_requirements()
     upgrade_op.print_optimisations()
     upgrade_op.print_upgrade_actions()
     upgrade_op.print_affected_revlogs()