pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  With updating the format of statefiles to use cbor, there can be cases when a
  user updates hg in between a unresolved graft, rebase, histedit, cbor load
  function in new hg won't be able to parse that properly. So let's fallback to
  reading the file old way if cbor fails or does not returns a dictionary as 
cbor
  may read that data without any error.

REPOSITORY
  rHG Mercurial

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 Exception("cbor parsed it wrong")
+                    return ret
+        except:     # 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: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to