Mercurial > public > mercurial-scm > hg
diff mercurial/dirstatemap.py @ 50720:bfbd84c57bda stable
dirstate-v2: actually fix the dirstate-v2 upgrade race
It looks like the previous fix for the dirstate-v2 upgrade race didn't work.
The problem is that it only recovers in case the size of the v1 `dirstate` file
is smaller than the `v2` one, whereas in real life it's always larger.
This commit changes the test to be more realistic, which reveals the crash,
and changes the code to fix the crash.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Mon, 26 Jun 2023 11:21:43 +0100 |
parents | a41eeb877d07 |
children | d718eddf01d9 |
line wrap: on
line diff
--- a/mercurial/dirstatemap.py Thu Jun 22 14:24:45 2023 +0200 +++ b/mercurial/dirstatemap.py Mon Jun 26 11:21:43 2023 +0100 @@ -4,7 +4,6 @@ # GNU General Public License version 2 or any later version. -import struct from .i18n import _ from . import ( @@ -152,15 +151,13 @@ b'dirstate only has a docket in v2 format' ) self._set_identity() - try: + data = self._readdirstatefile() + if data == b'' or data.startswith(docketmod.V2_FORMAT_MARKER): self._docket = docketmod.DirstateDocket.parse( - self._readdirstatefile(), self._nodeconstants + data, self._nodeconstants ) - except struct.error: - self._ui.debug(b"failed to read dirstate-v2 data") - raise error.CorruptedDirstate( - b"failed to read dirstate-v2 data" - ) + else: + raise error.CorruptedDirstate(b"dirstate is not in v2 format") return self._docket def _read_v2_data(self):