changeset 39711:cb2dcfa5cade

localrepo: move requirements reasonability testing to own function Just because we know how to handle each listed requirement doesn't mean that set of requirements is reasonable. This commit introduces an extension-wrappable function to validate that a set of requirements makes sense. We could combine this with ensurerequirementsrecognized(). But I think having a line between basic membership testing and compatibility checking is more powerful as it will help differentiate between missing support and buggy behavior. Differential Revision: https://phab.mercurial-scm.org/D4571
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 12 Sep 2018 15:03:17 -0700
parents 6192980553b4
children 9de1a1c83cd7
files mercurial/localrepo.py mercurial/statichttprepo.py
diffstat 2 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Wed Sep 12 15:47:24 2018 -0700
+++ b/mercurial/localrepo.py	Wed Sep 12 15:03:17 2018 -0700
@@ -431,8 +431,13 @@
         extensions.loadall(ui)
 
     supportedrequirements = gathersupportedrequirements(ui)
+
+    # We first validate the requirements are known.
     ensurerequirementsrecognized(requirements, supportedrequirements)
 
+    # Then we validate that the known set is reasonable to use together.
+    ensurerequirementscompatible(ui, requirements)
+
     # At this point, we know we should be capable of opening the repository.
     # Now get on with doing that.
 
@@ -494,6 +499,24 @@
             hint=_(b'see https://mercurial-scm.org/wiki/MissingRequirement '
                    b'for more information'))
 
+def ensurerequirementscompatible(ui, requirements):
+    """Validates that a set of recognized requirements is mutually compatible.
+
+    Some requirements may not be compatible with others or require
+    config options that aren't enabled. This function is called during
+    repository opening to ensure that the set of requirements needed
+    to open a repository is sane and compatible with config options.
+
+    Extensions can monkeypatch this function to perform additional
+    checking.
+
+    ``error.RepoError`` should be raised on failure.
+    """
+    if b'exp-sparse' in requirements and not sparse.enabled:
+        raise error.RepoError(_(b'repository is using sparse feature but '
+                                b'sparse is not enabled; enable the '
+                                b'"sparse" extensions to access'))
+
 @interfaceutil.implementer(repository.completelocalrepository)
 class localrepository(object):
 
@@ -625,11 +648,6 @@
             if inst.errno != errno.ENOENT:
                 raise
 
-        if 'exp-sparse' in self.requirements and not sparse.enabled:
-            raise error.RepoError(_('repository is using sparse feature but '
-                                    'sparse is not enabled; enable the '
-                                    '"sparse" extensions to access'))
-
         self.store = store.store(
             self.requirements, self.sharedpath,
             lambda base: vfsmod.vfs(base, cacheaudited=True))
--- a/mercurial/statichttprepo.py	Wed Sep 12 15:47:24 2018 -0700
+++ b/mercurial/statichttprepo.py	Wed Sep 12 15:03:17 2018 -0700
@@ -176,6 +176,7 @@
         supportedrequirements = localrepo.gathersupportedrequirements(ui)
         localrepo.ensurerequirementsrecognized(requirements,
                                                supportedrequirements)
+        localrepo.ensurerequirementscompatible(ui, requirements)
 
         # setup store
         self.store = store.store(requirements, self.path, vfsclass)