[PATCH 04 of 10] repair: identify repository deficiencies

Gregory Szorc gregory.szorc at gmail.com
Sun Nov 6 00:40:20 EDT 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1478382332 25200
#      Sat Nov 05 14:45:32 2016 -0700
# Node ID 7518e68e2f8276e85fb68174b3055a9dd16c665d
# Parent  9daec9c7adabe8c84cf2c01fc938e010ee4884d6
repair: identify repository deficiencies

A command that upgrades repositories but doesn't say what it is doing
or why it is doing it is less helpful than a command that does. So,
we start the implementation of repository upgrades by introducing
detection of sub-optimal repository state. Deficiencies with the
existing repository are now printed at the beginning of command
execution.

The added function returns a set of planned upgrade actions. This
variable will be used by subsequent patches.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3756,7 +3756,7 @@ def debugupgraderepo(ui, repo, **opts):
 
     At times during the upgrade, the repository may not be readable.
     """
-    raise error.Abort(_('not yet implemented'))
+    return repair.upgraderepo(ui, repo, dryrun=opts.get('dry_run'))
 
 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True)
 def debugwalk(ui, repo, *pats, **opts):
diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -360,3 +360,57 @@ def deleteobsmarkers(obsstore, indices):
         newobsstorefile.write(bytes)
     newobsstorefile.close()
     return n
+
+def upgradefinddeficiencies(repo):
+    """Obtain deficiencies with the existing repo and planned actions to fix.
+
+    Returns a list of strings that will be printed to the user and a set
+    of machine-readable actions that will be acted on later.
+    """
+    l = []
+    actions = set()
+
+    # We could detect lack of revlogv1 and store here, but they were added
+    # in 0.9.2 and we don't support upgrading repos without these
+    # requirements, so let's not bother.
+
+    if 'fncache' not in repo.requirements:
+        l.append(_('not using fncache; long and reserved filenames '
+                   'may not work correctly'))
+        actions.add('fncache')
+
+    if 'dotencode' not in repo.requirements:
+        l.append(_('not using dotencode; filenames beginning with '
+                   'a period or space may not work correctly'))
+        actions.add('dotencode')
+
+    if 'generaldelta' not in repo.requirements:
+        l.append(_('not using generaldelta storage; repository is larger '
+                   'and slower than it could be, pulling from '
+                   'generaldelta repositories will be slow'))
+        actions.add('generaldelta')
+
+    cl = repo.changelog
+    for rev in cl:
+        chainbase = cl.chainbase(rev)
+        if chainbase != rev:
+            l.append(_('changelog using delta chains; changelog reading '
+                       'is slower than it could be'))
+            actions.add('removecldeltachain')
+            break
+
+    return l, actions
+
+def upgraderepo(ui, repo, dryrun=False):
+    """Upgrade a repository in place."""
+    repo = repo.unfiltered()
+    deficiencies, actions = upgradefinddeficiencies(repo)
+
+    if deficiencies:
+        ui.write(_('the following deficiencies with the existing repository '
+                   'have been identified:\n\n'))
+
+        for d in deficiencies:
+            ui.write('* %s\n' % d)
+    else:
+        ui.write(_('no obvious deficiencies found in existing repository\n'))
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
@@ -1,5 +1,18 @@
   $ hg init empty
   $ cd empty
   $ hg debugupgraderepo
-  abort: not yet implemented
-  [255]
+  no obvious deficiencies found in existing repository
+
+Various sub-optimal detections work
+
+  $ cat > .hg/requires << EOF
+  > revlogv1
+  > store
+  > EOF
+
+  $ hg debugupgraderepo
+  the following deficiencies with the existing repository have been identified:
+  
+  * not using fncache; long and reserved filenames may not work correctly
+  * not using dotencode; filenames beginning with a period or space may not work correctly
+  * not using generaldelta storage; repository is larger and slower than it could be, pulling from generaldelta repositories will be slow


More information about the Mercurial-devel mailing list