# HG changeset patch # User Pierre-Yves David # Date 2021-04-16 13:39:00 # Node ID a3720569a43fe0be36cf15d69060e423545200d5 # Parent 99aed233aa8d873f6f2e3249b7e086a9df9227b6 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 diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py --- a/mercurial/revlogutils/nodemap.py +++ b/mercurial/revlogutils/nodemap.py @@ -53,7 +53,11 @@ def persisted_data(revlog): 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: diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t --- a/tests/test-persistent-nodemap.t +++ b/tests/test-persistent-nodemap.t @@ -799,9 +799,13 @@ truncate the file 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