dirstate-v2: add an option to prevent unintentional slow dirstate-v2
This is the project policy discussed in November 2020 and already put to use for
the persistent nodemap.
Differential Revision: https://phab.mercurial-scm.org/D11668
--- a/mercurial/configitems.py Thu Oct 14 22:35:46 2021 -0700
+++ b/mercurial/configitems.py Fri Oct 15 01:27:39 2021 +0200
@@ -1885,6 +1885,13 @@
default=b'skip',
experimental=True,
)
+# experimental as long as format.exp-dirstate-v2 is.
+coreconfigitem(
+ b'storage',
+ b'dirstate-v2.slow-path',
+ default=b"abort",
+ experimental=True,
+)
coreconfigitem(
b'storage',
b'new-repo-backend',
--- a/mercurial/dirstate.py Thu Oct 14 22:35:46 2021 -0700
+++ b/mercurial/dirstate.py Fri Oct 15 01:27:39 2021 +0200
@@ -39,6 +39,8 @@
parsers = policy.importmod('parsers')
rustmod = policy.importrust('dirstate')
+HAS_FAST_DIRSTATE_V2 = rustmod is not None
+
propertycache = util.propertycache
filecache = scmutil.filecache
_rangemask = dirstatemap.rangemask
--- a/mercurial/localrepo.py Thu Oct 14 22:35:46 2021 -0700
+++ b/mercurial/localrepo.py Fri Oct 15 01:27:39 2021 +0200
@@ -1174,6 +1174,32 @@
if slow_path == b'abort':
raise error.Abort(msg, hint=hint)
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 not in (b'allow', b'warn', b'abort'):
+ default = ui.config_default(b'storage', b'dirstate-v2.slow-path')
+ msg = _(b'unknown value for config "dirstate-v2.slow-path": "%s"\n')
+ ui.warn(msg % slow_path)
+ if not ui.quiet:
+ ui.warn(_(b'falling back to default value: %s\n') % default)
+ slow_path = default
+
+ msg = _(
+ b"accessing `dirstate-v2` repository without associated "
+ b"fast implementation."
+ )
+ hint = _(
+ b"check `hg help config.format.exp-dirstate-v2` " b"for details"
+ )
+ if not dirstate.HAS_FAST_DIRSTATE_V2:
+ if slow_path == b'warn':
+ msg = b"warning: " + msg + b'\n'
+ ui.warn(msg)
+ if not ui.quiet:
+ hint = b'(' + hint + b')\n'
+ ui.warn(hint)
+ if slow_path == b'abort':
+ raise error.Abort(msg, hint=hint)
if ui.configbool(b'storage', b'revlog.persistent-nodemap.mmap'):
options[b'persistent-nodemap.mmap'] = True
if ui.configbool(b'devel', b'persistent-nodemap'):
--- a/tests/test-dirstate-race.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-dirstate-race.t Fri Oct 15 01:27:39 2021 +0200
@@ -1,8 +1,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
$ hg init repo
--- a/tests/test-dirstate-race2.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-dirstate-race2.t Fri Oct 15 01:27:39 2021 +0200
@@ -1,8 +1,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
Checking the size/permissions/file-type of files stored in the
--- a/tests/test-dirstate.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-dirstate.t Fri Oct 15 01:27:39 2021 +0200
@@ -1,8 +1,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
------ Test dirstate._dirs refcounting
--- a/tests/test-hgignore.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-hgignore.t Fri Oct 15 01:27:39 2021 +0200
@@ -1,8 +1,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
$ hg init ignorerepo
--- a/tests/test-permissions.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-permissions.t Fri Oct 15 01:27:39 2021 +0200
@@ -3,8 +3,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
$ hg init t
--- a/tests/test-purge.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-purge.t Fri Oct 15 01:27:39 2021 +0200
@@ -1,8 +1,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
init
--- a/tests/test-status.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-status.t Fri Oct 15 01:27:39 2021 +0200
@@ -1,8 +1,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
$ hg init repo1
--- a/tests/test-symlinks.t Thu Oct 14 22:35:46 2021 -0700
+++ b/tests/test-symlinks.t Fri Oct 15 01:27:39 2021 +0200
@@ -3,8 +3,12 @@
#testcases dirstate-v1 dirstate-v2
#if dirstate-v2
- $ echo '[format]' >> $HGRCPATH
- $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [format]
+ > exp-dirstate-v2=1
+ > [storage]
+ > dirstate-v2.slow-path=allow
+ > EOF
#endif
== tests added in 0.7 ==