changeset 46971:a3720569a43f

nodemap: deal with data mmap error If the file is too small, the mmapread call would raise a ValueError. We catch that and ignore nodemap content (as we do without mmap). This make the repository slightly slower (until the next write) but usable. Unlike the current crash. Differential Revision: https://phab.mercurial-scm.org/D10458
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 16 Apr 2021 15:39:00 +0200
parents 99aed233aa8d
children 6904a9f33b30
files mercurial/revlogutils/nodemap.py tests/test-persistent-nodemap.t
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlogutils/nodemap.py	Fri Apr 16 14:59:13 2021 +0200
+++ b/mercurial/revlogutils/nodemap.py	Fri Apr 16 15:39:00 2021 +0200
@@ -53,7 +53,11 @@
     try:
         with revlog.opener(filename) as fd:
             if use_mmap:
-                data = util.buffer(util.mmapread(fd, data_length))
+                try:
+                    data = util.buffer(util.mmapread(fd, data_length))
+                except ValueError:
+                    # raised when the read file is too small
+                    data = b''
             else:
                 data = fd.read(data_length)
     except (IOError, OSError) as e:
--- a/tests/test-persistent-nodemap.t	Fri Apr 16 14:59:13 2021 +0200
+++ b/tests/test-persistent-nodemap.t	Fri Apr 16 15:39:00 2021 +0200
@@ -799,9 +799,13 @@
 
 Check that Mercurial reaction to this event
 
-  $ hg -R corruption-test-repo log -r .
-  abort: index 00changelog.i is corrupted
-  [50]
+  $ hg -R corruption-test-repo log -r . --traceback
+  changeset:   5005:90d5d3ba2fc4
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     a2
+  
 
 
 stream clone