diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py --- a/mercurial/upgrade.py +++ b/mercurial/upgrade.py @@ -118,6 +118,7 @@ up_actions, removed_actions, revlogs, + backup, ) if not run: @@ -215,12 +216,6 @@ backuppath = upgrade_engine.upgrade( ui, repo, dstrepo, upgrade_op ) - if not backup: - ui.status( - _(b'removing old repository content %s\n') % backuppath - ) - repo.vfs.rmtree(backuppath, forcibly=True) - backuppath = None finally: ui.status(_(b'removing temporary repository %s\n') % tmppath) 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 @@ -626,6 +626,7 @@ upgrade_actions, removed_actions, revlogs_to_process, + backup_store, ): self.ui = ui self.new_requirements = new_requirements @@ -670,6 +671,9 @@ b're-delta-multibase' in self._upgrade_actions_names ) + # should this operation create a backup of the store + self.backup_store = backup_store + def _write_labeled(self, l, label): """ Utility function to aid writing of a list under one label 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 @@ -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 diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t --- a/tests/test-upgrade-repo.t +++ b/tests/test-upgrade-repo.t @@ -632,11 +632,9 @@ data fully upgraded in a temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data - replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) replacing store... store replacement complete; repository was inconsistent for * (glob) finalizing requirements file and making repository readable again - removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob) $ ls -1 .hg/ | grep upgradebackup [1] @@ -679,11 +677,9 @@ data fully upgraded in a temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data - replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) replacing store... store replacement complete; repository was inconsistent for *s (glob) finalizing requirements file and making repository readable again - removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob) Check that the repo still works fine @@ -759,11 +755,9 @@ data fully upgraded in a temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data - replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) replacing store... store replacement complete; repository was inconsistent for *s (glob) finalizing requirements file and making repository readable again - removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob) $ hg verify checking changesets @@ -810,11 +804,9 @@ data fully upgraded in a temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data - replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) replacing store... store replacement complete; repository was inconsistent for *s (glob) finalizing requirements file and making repository readable again - removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob) $ hg verify checking changesets @@ -861,11 +853,9 @@ data fully upgraded in a temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data - replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) replacing store... store replacement complete; repository was inconsistent for *s (glob) finalizing requirements file and making repository readable again - removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob) $ hg verify checking changesets @@ -919,11 +909,9 @@ data fully upgraded in a temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data - replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) replacing store... store replacement complete; repository was inconsistent for *s (glob) finalizing requirements file and making repository readable again - removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob) $ hg verify checking changesets @@ -978,11 +966,9 @@ data fully upgraded in a temporary repository marking source repository as being upgraded; clients will be unable to read from repository starting in-place swap of repository data - replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) replacing store... store replacement complete; repository was inconsistent for *s (glob) finalizing requirements file and making repository readable again - removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob) removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob) $ hg verify checking changesets