mmap: only use mmap to read revlog index if it is safe stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 03 Jul 2024 12:26:57 +0200
branchstable
changeset 51653 d6c895e4adc4
parent 51652 ba205f944cb4
child 51654 c0e30a019ce1
mmap: only use mmap to read revlog index if it is safe Cf `is_mmap_safe` docstring.
mercurial/revlog.py
tests/test-revlog-mmapindex.t
--- a/mercurial/revlog.py	Wed Jul 03 12:22:48 2024 +0200
+++ b/mercurial/revlog.py	Wed Jul 03 12:26:57 2024 +0200
@@ -1460,7 +1460,10 @@
             with self.opener(filepath) as fp:
                 if mmap_threshold is not None:
                     file_size = self.opener.fstat(fp).st_size
-                    if file_size >= mmap_threshold:
+                    if (
+                        file_size >= mmap_threshold
+                        and self.opener.is_mmap_safe(filepath)
+                    ):
                         if size is not None:
                             # avoid potentiel mmap crash
                             size = min(file_size, size)
--- a/tests/test-revlog-mmapindex.t	Wed Jul 03 12:22:48 2024 +0200
+++ b/tests/test-revlog-mmapindex.t	Wed Jul 03 12:26:57 2024 +0200
@@ -37,7 +37,7 @@
 
 mmap index which is now more than 4k long
   $ hg log -l 5 -T '{rev}\n' --config experimental.mmapindexthreshold=4k
-  mmapping $TESTTMP/a/.hg/store/00changelog.i
+  mmapping $TESTTMP/a/.hg/store/00changelog.i (no-pure !)
   mmapping $TESTTMP/a/.hg/store/00changelog-????????.nd (glob) (rust !)
   100
   99