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