Patchwork [2,of,2,V2] debugupgraderepo: add a --no-backup mode

login
register
mail settings
Submitter Boris Feld
Date Dec. 31, 2018, 3:19 p.m.
Message ID <106c008b2e1c77791cf2.1546269564@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/37403/
State Accepted
Headers show

Comments

Boris Feld - Dec. 31, 2018, 3:19 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1545394678 -3600
#      Fri Dec 21 13:17:58 2018 +0100
# Node ID 106c008b2e1c77791cf231316be2112160b4402e
# Parent  0713443cf6e40b7e6409cdd898d5ba22b4d02e48
# EXP-Topic upgrade-test
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 106c008b2e1c
debugupgraderepo: add a --no-backup mode

The process has been around for a while and is pretty safe now. Having an
automated way to clean up the old data is useful when running many different
conversion to compare delta algorithm.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2751,8 +2751,9 @@  def debugupdatecaches(ui, repo, *pats, *
 @command('debugupgraderepo', [
     ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')),
     ('', 'run', False, _('performs an upgrade')),
+    ('', 'backup', True, _('keep the old repository content around')),
 ])
-def debugupgraderepo(ui, repo, run=False, optimize=None):
+def debugupgraderepo(ui, repo, run=False, optimize=None, backup=True):
     """upgrade a repository to use different features
 
     If no arguments are specified, the repository is evaluated for upgrade
@@ -2771,7 +2772,8 @@  def debugupgraderepo(ui, repo, run=False
     should complete almost instantaneously and the chances of a consumer being
     unable to access the repository should be low.
     """
-    return upgrade.upgraderepo(ui, repo, run=run, optimize=optimize)
+    return upgrade.upgraderepo(ui, repo, run=run, optimize=optimize,
+                               backup=backup)
 
 @command('debugwalk', cmdutil.walkopts, _('[OPTION]... [FILE]...'),
          inferrepo=True)
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -742,7 +742,7 @@  def _upgraderepo(ui, srcrepo, dstrepo, r
 
     return backuppath
 
-def upgraderepo(ui, repo, run=False, optimize=None):
+def upgraderepo(ui, repo, run=False, optimize=None, backup=True):
     """Upgrade a repository in place."""
     if optimize is None:
         optimize = []
@@ -899,6 +899,10 @@  def upgraderepo(ui, repo, run=False, opt
             with dstrepo.wlock(), dstrepo.lock():
                 backuppath = _upgraderepo(ui, repo, dstrepo, newreqs,
                                           upgradeactions)
+            if not (backup or backuppath is None):
+                ui.write(_('removing old repository content%s\n') % backuppath)
+                repo.vfs.rmtree(backuppath, forcibly=True)
+                backuppath = None
 
         finally:
             ui.write(_('removing temporary repository %s\n') % tmppath)
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -299,7 +299,7 @@  Show all commands + options
   debuguigetpass: prompt
   debuguiprompt: prompt
   debugupdatecaches: 
-  debugupgraderepo: optimize, run
+  debugupgraderepo: optimize, run, backup
   debugwalk: include, exclude
   debugwhyunstable: 
   debugwireargs: three, four, five, ssh, remotecmd, insecure
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
@@ -453,6 +453,8 @@  verify should be happy
 
 old store should be backed up
 
+  $ ls -d .hg/upgradebackup.*/
+  .hg/upgradebackup.*/ (glob)
   $ ls .hg/upgradebackup.*/store
   00changelog.i
   00manifest.i
@@ -464,8 +466,47 @@  old store should be backed up
   undo.backupfiles
   undo.phaseroots
 
+unless --no-backup is passed
+
+  $ rm -rf .hg/upgradebackup.*/
+  $ hg debugupgraderepo --run --no-backup
+  upgrade will perform the following actions:
+  
+  requirements
+     preserved: dotencode, fncache, generaldelta, revlogv1, store
+     added: sparserevlog
+  
+  sparserevlog
+     Revlog supports delta chain with more unused data between payload. These gaps will be skipped at read time. This allows for better delta chains, making a better compression and faster exchange with server.
+  
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage migrated data: $TESTTMP/upgradegd/.hg/upgrade.* (glob)
+  (it is safe to interrupt this process any time before data migration completes)
+  migrating 9 total revisions (3 in filelogs, 3 in manifests, 3 in changelog)
+  migrating 917 bytes in store; 401 bytes tracked data
+  migrating 3 filelogs containing 3 revisions (192 bytes in store; 0 bytes tracked data)
+  finished migrating 3 filelog revisions across 3 filelogs; change in size: 0 bytes
+  migrating 1 manifests containing 3 revisions (349 bytes in store; 220 bytes tracked data)
+  finished migrating 3 manifest revisions across 1 manifests; change in size: 0 bytes
+  migrating changelog containing 3 revisions (376 bytes in store; 181 bytes tracked data)
+  finished migrating 3 changelog revisions; change in size: 0 bytes
+  finished migrating 9 total revisions; total change in store size: 0 bytes
+  copying phaseroots
+  data fully migrated to 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 0.0s
+  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]
   $ cd ..
 
+
 store files with special filenames aren't encoded during copy
 
   $ hg init store-filenames