Patchwork D9487: upgrade: start moving the "to be happening" data in a dedicated object

login
register
mail settings
Submitter phabricator
Date Dec. 1, 2020, 10:12 p.m.
Message ID <differential-rev-PHID-DREV-plzs2hnb27uk6hqmj5hz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47769/
State Superseded
Headers show

Comments

phabricator - Dec. 1, 2020, 10:12 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




To: marmoute, #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
@@ -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
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
@@ -534,6 +534,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. #
 
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -176,6 +176,13 @@ 
                 ui.write((b'  - %s\n' % r))
         ui.write((b'\n'))
 
+    upgrade_op = upgrade_actions.UpgradeOperation(
+        newreqs,
+        [a.name for a in actions],
+        revlogs,
+    )
+    upgrade_op
+
     if not run:
         fromconfig = []
         onlydefault = []
@@ -249,8 +256,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 +281,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(