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

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Mon Mar 26 13:09:32 EDT 2018


pulkit updated this revision to Diff 7300.

REPOSITORY
  rHG Mercurial

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

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
@@ -83,8 +83,17 @@
     def _read(self):
         """reads the state 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) or
+                        ret.get('magicheader') != 'HGStateFile'):
+                        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 state file if exists"""



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


More information about the Mercurial-devel mailing list