changeset 46056:c407513a44a3

upgrade: start moving the "to be happening" data in a dedicated object The upgrade code has a lot of logic to determine which action needs to be performed depending of various element (sometimes depending from each other). It would be nice to have a consistent object representing this. That could be cleanly passed and avoid some logic duplication. So we create this object as a start. Differential Revision: https://phab.mercurial-scm.org/D9487
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 01 Dec 2020 22:37:34 +0100
parents 7740d5102760
children e0313b0a6f7e
files mercurial/upgrade.py mercurial/upgrade_utils/actions.py mercurial/upgrade_utils/engine.py
diffstat 3 files changed, 27 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/upgrade.py	Sun Dec 06 20:38:01 2020 -0500
+++ b/mercurial/upgrade.py	Tue Dec 01 22:37:34 2020 +0100
@@ -176,6 +176,12 @@
                 ui.write((b'  - %s\n' % r))
         ui.write((b'\n'))
 
+    upgrade_op = upgrade_actions.UpgradeOperation(
+        newreqs,
+        [a.name for a in actions],
+        revlogs,
+    )
+
     if not run:
         fromconfig = []
         onlydefault = []
@@ -249,8 +255,6 @@
     printupgradeactions()
     print_affected_revlogs()
 
-    upgradeactions = [a.name for a in actions]
-
     ui.status(_(b'beginning upgrade...\n'))
     with repo.wlock(), repo.lock():
         ui.status(_(b'repository locked and read-only\n'))
@@ -276,7 +280,7 @@
 
             with dstrepo.wlock(), dstrepo.lock():
                 backuppath = upgrade_engine.upgrade(
-                    ui, repo, dstrepo, newreqs, upgradeactions, revlogs=revlogs
+                    ui, repo, dstrepo, upgrade_op
                 )
             if not (backup or backuppath is None):
                 ui.status(
--- a/mercurial/upgrade_utils/actions.py	Sun Dec 06 20:38:01 2020 -0500
+++ b/mercurial/upgrade_utils/actions.py	Tue Dec 01 22:37:34 2020 +0100
@@ -554,6 +554,15 @@
     return newactions
 
 
+class UpgradeOperation(object):
+    """represent the work to be done during an upgrade"""
+
+    def __init__(self, requirements, actions, revlogs_to_process):
+        self.requirements = requirements
+        self.actions = actions
+        self.revlogs_to_process = revlogs_to_process
+
+
 ###  Code checking if a repository can got through the upgrade process at all. #
 
 
--- a/mercurial/upgrade_utils/engine.py	Sun Dec 06 20:38:01 2020 -0500
+++ b/mercurial/upgrade_utils/engine.py	Tue Dec 01 22:37:34 2020 +0100
@@ -383,9 +383,7 @@
     """
 
 
-def upgrade(
-    ui, srcrepo, dstrepo, requirements, actions, revlogs=UPGRADE_ALL_REVLOGS
-):
+def upgrade(ui, srcrepo, dstrepo, upgrade_op):
     """Do the low-level work of upgrading a repository.
 
     The upgrade is effectively performed as a copy between a source
@@ -405,13 +403,13 @@
         )
     )
 
-    if b're-delta-all' in actions:
+    if b're-delta-all' in upgrade_op.actions:
         deltareuse = revlog.revlog.DELTAREUSENEVER
-    elif b're-delta-parent' in actions:
+    elif b're-delta-parent' in upgrade_op.actions:
         deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-    elif b're-delta-multibase' in actions:
+    elif b're-delta-multibase' in upgrade_op.actions:
         deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-    elif b're-delta-fulladd' in actions:
+    elif b're-delta-fulladd' in upgrade_op.actions:
         deltareuse = revlog.revlog.DELTAREUSEFULLADD
     else:
         deltareuse = revlog.revlog.DELTAREUSEALWAYS
@@ -423,14 +421,16 @@
             dstrepo,
             tr,
             deltareuse,
-            b're-delta-multibase' in actions,
-            revlogs=revlogs,
+            b're-delta-multibase' in upgrade_op.actions,
+            revlogs=upgrade_op.revlogs_to_process,
         )
 
     # Now copy other files in the store directory.
     # The sorted() makes execution deterministic.
     for p, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)):
-        if not _filterstorefile(srcrepo, dstrepo, requirements, p, kind, st):
+        if not _filterstorefile(
+            srcrepo, dstrepo, upgrade_op.requirements, p, kind, st
+        ):
             continue
 
         srcrepo.ui.status(_(b'copying %s\n') % p)
@@ -489,7 +489,7 @@
             b'again\n'
         )
     )
-    scmutil.writereporequirements(srcrepo, requirements)
+    scmutil.writereporequirements(srcrepo, upgrade_op.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