D2592: state: add registrar to register function to read old state files
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Mon Mar 26 13:09:09 EDT 2018
pulkit updated this revision to Diff 7298.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D2592?vs=6443&id=7298
REVISION DETAIL
https://phab.mercurial-scm.org/D2592
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
@@ -22,6 +22,7 @@
from .thirdparty import cbor
from . import (
+ error,
util,
)
@@ -91,3 +92,23 @@
def exists(self):
"""check whether the state 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."""
+ if path in oldstatefilefns:
+ raise error.ProgrammingError("duplicate entry for reading old %s"
+ " found" % path)
+ oldstatefilefns[path] = func
+ return func
+ return dec
To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel
More information about the Mercurial-devel
mailing list