changeset 52694:bbbb12632607

slow-path: add a generic "all-slow-path" option This provide a generic config to change the slow-path behavior in a future proof way. Useful for automation and conversion.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 09 Dec 2024 06:23:34 +0100
parents 3b0625a3f04a
children b7afc38468bd b12a4b9d09ce
files mercurial/configitems.toml mercurial/helptext/config.txt mercurial/localrepo.py tests/test-persistent-nodemap.t
diffstat 4 files changed, 67 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/configitems.toml	Mon Dec 09 06:23:29 2024 +0100
+++ b/mercurial/configitems.toml	Mon Dec 09 06:23:34 2024 +0100
@@ -2185,8 +2185,31 @@
 
 [[items]]
 section = "storage"
+name = "all-slow-path"
+default = "abort"
+documentation = """Control the behavior of Mercurial when lacking performant code
+
+Some format features might only have a fast implementation when a specific
+flavor is installed (e.g. when the Rust extensions are available). A slow pure
+Python implementation might be available to help with converting the repository
+to another format or to perform a few accesses in an automation context.
+Using such accesses might result in Mercurial becoming multiple time slower
+than usual.
+
+Acceptable values:
+
+``allow``: Silently use the slower implementation to access the repository.
+``warn``: Warn, but use the slower implementation to access the repository.
+``abort``: Prevent access to such repositories. (This is the default)
+
+See the individual "storage.*.slow-path" configs for details. These options can
+override the default.
+"""
+
+[[items]]
+section = "storage"
 name = "dirstate-v2.slow-path"
-default = "abort"
+default = "default"
 experimental = true  # experimental as long as format.use-dirstate-v2 is.
 documentation = """Control the behavior of Mercurial when using a repository with the "dirstate-v2"
 feature with an installation of Mercurial without a fast implementation for
@@ -2194,6 +2217,7 @@
 
 ``allow``: Silently use the slower implementation to access the repository.
 ``warn``: Warn, but use the slower implementation to access the repository.
+``default``: use value from the `storage.all-slow-path` value.
 ``abort``: Prevent access to such repositories. (This is the default)
 
 For details on the "dirstate-v2" feature, see:
@@ -2245,13 +2269,14 @@
 [[items]]
 section = "storage"
 name = "revlog.persistent-nodemap.slow-path"
-default = "abort"
+default = "default"
 documentation = """Control the behavior of Mercurial when using a repository with a "persistent"
 nodemap with an installation of Mercurial without a fast implementation for
 the feature:
 
 ``allow``: Silently use the slower implementation to access the repository.
 ``warn``: Warn, but use the slower implementation to access the repository.
+``default``: use the value from the `storage.all-slow-path` value.
 ``abort``: Prevent access to such repositories. (This is the default)
 
 For details on the "persistent-nodemap" feature, see:
--- a/mercurial/helptext/config.txt	Mon Dec 09 06:23:29 2024 +0100
+++ b/mercurial/helptext/config.txt	Mon Dec 09 06:23:34 2024 +0100
@@ -2325,6 +2325,9 @@
 Control the strategy Mercurial uses internally to store history. Options in this
 category impact performance and repository size.
 
+``all-slow-path``
+    :config-doc:`storage.all-slow-path`
+
 ``revlog.dirstate-v2.slow-path``
     :config-doc:`storage.dirstate-v2.slow-path`
 
--- a/mercurial/localrepo.py	Mon Dec 09 06:23:29 2024 +0100
+++ b/mercurial/localrepo.py	Mon Dec 09 06:23:34 2024 +0100
@@ -1173,10 +1173,10 @@
         slow_path = ui.config(
             b'storage', b'revlog.persistent-nodemap.slow-path'
         )
+        if slow_path == b'default':
+            slow_path = ui.config(b'storage', b'all-slow-path')
         if slow_path not in (b'allow', b'warn', b'abort'):
-            default = ui.config_default(
-                b'storage', b'revlog.persistent-nodemap.slow-path'
-            )
+            default = ui.config_default(b'storage', b'all-slow-path')
             msg = _(
                 b'unknown value for config '
                 b'"storage.revlog.persistent-nodemap.slow-path": "%s"\n'
@@ -1206,8 +1206,10 @@
         options[b'persistent-nodemap'] = True
     if requirementsmod.DIRSTATE_V2_REQUIREMENT in requirements:
         slow_path = ui.config(b'storage', b'dirstate-v2.slow-path')
+        if slow_path == b'default':
+            slow_path = ui.config(b'storage', b'all-slow-path')
         if slow_path not in (b'allow', b'warn', b'abort'):
-            default = ui.config_default(b'storage', b'dirstate-v2.slow-path')
+            default = ui.config_default(b'storage', b'all-slow-path')
             msg = _(b'unknown value for config "dirstate-v2.slow-path": "%s"\n')
             ui.warn(msg % slow_path)
             if not ui.quiet:
--- a/tests/test-persistent-nodemap.t	Mon Dec 09 06:23:29 2024 +0100
+++ b/tests/test-persistent-nodemap.t	Mon Dec 09 06:23:34 2024 +0100
@@ -24,7 +24,7 @@
   $ hg init test-repo --config storage.revlog.persistent-nodemap.slow-path=allow
   $ cd test-repo
 
-Check handling of the default slow-path value
+Check handling of the default slow-path value and its variants
 
 #if no-pure no-rust
 
@@ -33,6 +33,36 @@
   (check `hg help config.format.use-persistent-nodemap` for details)
   [255]
 
+  $ hg id \
+  >    --config storage.revlog.persistent-nodemap.slow-path=abort
+  abort: accessing `persistent-nodemap` repository without associated fast implementation.
+  (check `hg help config.format.use-persistent-nodemap` for details)
+  [255]
+
+  $ hg id \
+  >    --config storage.revlog.persistent-nodemap.slow-path=warn
+  warning: accessing `persistent-nodemap` repository without associated fast implementation.
+  (check `hg help config.format.use-persistent-nodemap` for details)
+  000000000000 tip
+
+  $ hg id \
+  >    --config storage.all-slow-path=warn
+  warning: accessing `persistent-nodemap` repository without associated fast implementation.
+  (check `hg help config.format.use-persistent-nodemap` for details)
+  000000000000 tip
+
+  $ hg id \
+  >    --config storage.all-slow-path=warn \
+  >    --config storage.revlog.persistent-nodemap.slow-path=abort
+  abort: accessing `persistent-nodemap` repository without associated fast implementation.
+  (check `hg help config.format.use-persistent-nodemap` for details)
+  [255]
+
+  $ hg id \
+  >    --config storage.all-slow-path=abort \
+  >    --config storage.revlog.persistent-nodemap.slow-path=allow
+  000000000000 tip
+
 Unlock further check (we are here to test the feature)
 
   $ cat << EOF >> $HGRCPATH