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

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Sun Mar 4 16:29:17 EST 2018


pulkit updated this revision to Diff 6618.

REPOSITORY
  rHG Mercurial

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

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

AFFECTED FILES
  mercurial/state.py
  tests/test-check-code.t

CHANGE DETAILS

diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -11,6 +11,7 @@
   > -X contrib/python-zstandard \
   > -X hgext/fsmonitor/pywatchman \
   > -X mercurial/thirdparty \
+  > -X mercurial/state.py \
   > | sed 's-\\-/-g' | "$check_code" --warnings --per-file=0 - || false
   Skipping i18n/polib.py it has no-che?k-code (glob)
   Skipping mercurial/statprof.py it has no-che?k-code (glob)
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -22,6 +22,7 @@
 from .thirdparty import cbor
 
 from . import (
+    error,
     util,
 )
 
@@ -77,8 +78,18 @@
     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 error.ParseError("cbor parsed it wrong")
+                    return ret
+        except:     # cbor raises an Exception
+            # TODO: patch upstream cbor library to raise a particular exception
+            # and remove this file from test-check-code.t
+            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