D2593: state: add logic to parse the state file in old way if cbor fails

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Mar 9 05:55:03 EST 2018


pulkit updated this revision to Diff 6759.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2593?vs=6618&id=6759

REVISION DETAIL
  https://phab.mercurial-scm.org/D2593

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -77,8 +77,16 @@
     def _read(self):
         """reads the evolvestate file and returns a dictionary which contain
         data in the same format as it was before storing"""
-        with self._repo.vfs(self.fname, 'rb') as fp:
-            return cbor.load(fp)
+        try:
+            with self._repo.vfs(self.fname, 'rb') as fp:
+                    ret = cbor.load(fp)
+                    if not isinstance(ret, dict):
+                        raise cbor.CBORDecodeError
+                    return ret
+        except cbor.CBORDecodeError:     # cbor raises an Exception
+            with self._repo.vfs(self.fname, 'rb') as fp:
+                oldfn = oldstatefilefns[self.fname]
+                return oldfn(fp)
 
     def delete(self):
         """drop the evolvestate file if exists"""



To: pulkit, #hg-reviewers
Cc: durin42, mercurial-devel


More information about the Mercurial-devel mailing list