diff mercurial/localrepo.py @ 46332:cc3452d2dfa4

share: rework config options to be much clearer and easier Recently I implemented various boolean configs which control how to behave when there is a share-safe mismatch between source and share repository. Mismatch means that source supports share-safe where as share does not or vice versa. However, while discussion and documentation we realized that it's too complicated and there are some combinations of values which makes no sense. We decided to introduce a config option with 4 possible values which makes controlling and understanding things easier. The config option `share.safe-mismatch.source-{not-}safe` can have following 4 values: * abort (default): error out if there is mismatch * allow: allow to work with respecting share source configuration * {up|down}grade-abort: try to {up|down}grade, if it fails, abort * {up|down}grade-allow: try to {up|down}grade, if it fails, continue in allow mode I am not sure if I can explain 3 config options which I deleted right now in just 5 lines which is a sign of how complex they became. No test changes demonstrate that functionality is same, only names have changed. Differential Revision: https://phab.mercurial-scm.org/D9785
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 18 Jan 2021 21:37:20 +0530
parents 8788981c95f8
children 2eb5fe13461b
line wrap: on
line diff
--- a/mercurial/localrepo.py	Thu Jan 14 21:34:12 2021 +0530
+++ b/mercurial/localrepo.py	Mon Jan 18 21:37:20 2021 +0530
@@ -575,8 +575,13 @@
             and requirementsmod.SHARESAFE_REQUIREMENT
             not in _readrequires(sharedvfs, True)
         ):
-            if ui.configbool(
-                b'experimental', b'sharesafe-auto-downgrade-shares'
+            mismatch_config = ui.config(
+                b'share', b'safe-mismatch.source-not-safe'
+            )
+            if mismatch_config in (
+                b'downgrade-allow',
+                b'allow',
+                b'downgrade-abort',
             ):
                 # prevent cyclic import localrepo -> upgrade -> localrepo
                 from . import upgrade
@@ -586,19 +591,38 @@
                     hgvfs,
                     sharedvfs,
                     requirements,
+                    mismatch_config,
                 )
-            else:
+            elif mismatch_config == b'abort':
                 raise error.Abort(
                     _(
                         b"share source does not support exp-sharesafe requirement"
                     )
                 )
+            else:
+                hint = _(
+                    "run `hg help config.share.safe-mismatch.source-not-safe`"
+                )
+                raise error.Abort(
+                    _(
+                        b"share-safe mismatch with source.\nUnrecognized"
+                        b" value '%s' of `share.safe-mismatch.source-not-safe`"
+                        b" set."
+                    )
+                    % mismatch_config,
+                    hint=hint,
+                )
         else:
             requirements |= _readrequires(storevfs, False)
     elif shared:
         sourcerequires = _readrequires(sharedvfs, False)
         if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
-            if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-shares'):
+            mismatch_config = ui.config(b'share', b'safe-mismatch.source-safe')
+            if mismatch_config in (
+                b'upgrade-allow',
+                b'allow',
+                b'upgrade-abort',
+            ):
                 # prevent cyclic import localrepo -> upgrade -> localrepo
                 from . import upgrade
 
@@ -607,14 +631,25 @@
                     hgvfs,
                     storevfs,
                     requirements,
+                    mismatch_config,
                 )
-            else:
+            elif mismatch_config == b'abort':
                 raise error.Abort(
                     _(
                         b'version mismatch: source uses share-safe'
                         b' functionality while the current share does not'
                     )
                 )
+            else:
+                hint = _("run `hg help config.share.safe-mismatch.source-safe`")
+                raise error.Abort(
+                    _(
+                        b"share-safe mismatch with source.\nUnrecognized"
+                        b" value '%s' of `share.safe-mismatch.source-safe` set."
+                    )
+                    % mismatch_config,
+                    hint=hint,
+                )
 
     # The .hg/hgrc file may load extensions or contain config options
     # that influence repository construction. Attempt to load it and