Mercurial > public > mercurial-scm > hg-stable
diff mercurial/upgrade_utils/engine.py @ 46447:2e8a844d0ae0
upgrade: don't create store backup if `--no-backup` is passed
If the user explicitly mentioned that they don't need backup, then let's not
create it.
Differential Revision: https://phab.mercurial-scm.org/D9770
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 14 Jan 2021 16:25:40 +0530 |
parents | 8023991dc811 |
children | ee9002b99595 |
line wrap: on
line diff
--- a/mercurial/upgrade_utils/engine.py Mon Dec 14 10:44:29 2020 +0100 +++ b/mercurial/upgrade_utils/engine.py Thu Jan 14 16:25:40 2021 +0530 @@ -412,7 +412,10 @@ """ # 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')) + if upgrade_op.backup_store: + util.rename(currentrepo.spath, backupvfs.join(b'store')) + else: + currentrepo.vfs.rmtree(b'store', forcibly=True) util.rename(upgradedrepo.spath, currentrepo.spath) @@ -436,6 +439,8 @@ """ assert srcrepo.currentwlock() assert dstrepo.currentwlock() + backuppath = None + backupvfs = None ui.status( _( @@ -464,11 +469,16 @@ ui.status(_(b'data fully upgraded in a temporary repository\n')) - backuppath = pycompat.mkdtemp(prefix=b'upgradebackup.', dir=srcrepo.path) - backupvfs = vfsmod.vfs(backuppath) + if upgrade_op.backup_store: + backuppath = pycompat.mkdtemp( + prefix=b'upgradebackup.', dir=srcrepo.path + ) + backupvfs = vfsmod.vfs(backuppath) - # Make a backup of requires file first, as it is the first to be modified. - util.copyfile(srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires')) + # Make a backup of requires file first, as it is the first to be modified. + util.copyfile( + srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires') + ) # We install an arbitrary requirement that clients must not support # as a mechanism to lock out new clients during the data swap. This is @@ -485,7 +495,8 @@ ) ui.status(_(b'starting in-place swap of repository data\n')) - ui.status(_(b'replaced files will be backed up at %s\n') % backuppath) + if upgrade_op.backup_store: + ui.status(_(b'replaced files will be backed up at %s\n') % backuppath) # Now swap in the new store directory. Doing it as a rename should make # the operation nearly instantaneous and atomic (at least in well-behaved @@ -512,10 +523,11 @@ ) 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 - # could update srcrepo.svfs and other variables to point to the new - # location. This is simpler. - backupvfs.unlink(b'store/lock') + if upgrade_op.backup_store: + # 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 + # could update srcrepo.svfs and other variables to point to the new + # location. This is simpler. + backupvfs.unlink(b'store/lock') return backuppath