engine: refactor code to replace stores in separate function
authorPulkit Goyal <7895pulkit@gmail.com>
Thu, 31 Dec 2020 14:45:16 +0530
changeset 46220 1ca7865c245d
parent 46219 481d9aed669c
child 46221 0ca98ed828f9
engine: refactor code to replace stores in separate function In not all upgrades, we need to change the whole store. For example, when upgrading repository to share-safe mode, we don't touch revlogs at all hence store cloning and copying is not required. The store replacing code needs to be made aware about what all has changed and hence only copy/rename those things. To kickstart that, this patch moves existing logic into a separate function. Differential Revision: https://phab.mercurial-scm.org/D9674
mercurial/upgrade_utils/engine.py
--- a/mercurial/upgrade_utils/engine.py	Thu Dec 31 14:10:25 2020 +0530
+++ b/mercurial/upgrade_utils/engine.py	Thu Dec 31 14:45:16 2020 +0530
@@ -408,6 +408,25 @@
     return True
 
 
+def _replacestores(currentrepo, upgradedrepo, backupvfs, upgrade_op):
+    """Replace the stores after current repository is upgraded
+
+    Creates a backup of current repository store at backup path
+    Replaces upgraded store files in current repo from upgraded one
+
+    Arguments:
+      currentrepo: repo object of current repository
+      upgradedrepo: repo object of the upgraded data
+      backupvfs: vfs object for the backup path
+      upgrade_op: upgrade operation object
+                  to be used to decide what all is upgraded
+    """
+    # TODO: don't blindly rename everything in store
+    # There can be upgrades where store is not touched at all
+    util.rename(currentrepo.spath, backupvfs.join(b'store'))
+    util.rename(upgradedrepo.spath, currentrepo.spath)
+
+
 def finishdatamigration(ui, srcrepo, dstrepo, requirements):
     """Hook point for extensions to perform additional actions during upgrade.
 
@@ -490,8 +509,7 @@
     # environments).
     ui.status(_(b'replacing store...\n'))
     tstart = util.timer()
-    util.rename(srcrepo.spath, backupvfs.join(b'store'))
-    util.rename(dstrepo.spath, srcrepo.spath)
+    _replacestores(srcrepo, dstrepo, backupvfs, upgrade_op)
     elapsed = util.timer() - tstart
     ui.status(
         _(