# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2020-12-31 09:15:16 # Node ID 1ca7865c245db32f69e5b05b75489b7cae147f9b # Parent 481d9aed669ceb3441697125ae946cebb3282e11 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 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 @@ -408,6 +408,25 @@ def _filterstorefile(srcrepo, dstrepo, r 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 @@ def upgrade(ui, srcrepo, dstrepo, upgrad # 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( _(