Patchwork D2592: state: add registrar to register function to read old state files

login
register
mail settings
Submitter phabricator
Date March 3, 2018, 7:19 p.m.
Message ID <differential-rev-PHID-DREV-ukgiwwjk5xqth52rdjgy-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28800/
State New
Headers show

Comments

phabricator - March 3, 2018, 7:19 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - March 25, 2018, 6:21 a.m.
martinvonz added inline comments.

INLINE COMMENTS

> state.py:104
> +        should return a dict of data stored in state file."""
> +        assert path not in oldstatefilefns
> +        oldstatefilefns[path] = func

I think we're used ProgrammingError elsewhere for this kind of thing

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -87,3 +87,21 @@ 
     def exists(self):
         """check whether the evolvestate file exists or not"""
         return self._repo.vfs.exists(self.fname)
+
+oldstatefilefns = {}
+
+def readoldstatefile(path):
+    """decorator for registering function which can read the old format of state
+    files.
+
+    Using the state class defined above, all the state files will be using cbor
+    to serialize data to write to disk. But a user can update hg while in
+    conflict. This decorator registers function for reading old statefiles in
+    such cases."""
+    def dec(func):
+        """func here should accept the file object of the state file and
+        should return a dict of data stored in state file."""
+        assert path not in oldstatefilefns
+        oldstatefilefns[path] = func
+        return func
+    return dec