##// END OF EJS Templates
state: write the version number in plain text on top of state files...
Pulkit Goyal -
r38118:a0e4d654 default
parent child Browse files
Show More
@@ -22,6 +22,7 b' from __future__ import absolute_import'
22 from .thirdparty import cbor
22 from .thirdparty import cbor
23
23
24 from . import (
24 from . import (
25 error,
25 util,
26 util,
26 )
27 )
27
28
@@ -51,18 +52,28 b' class cmdstate(object):'
51 """read the existing state file and return a dict of data stored"""
52 """read the existing state file and return a dict of data stored"""
52 return self._read()
53 return self._read()
53
54
54 def save(self, data):
55 def save(self, version, data):
55 """write all the state data stored to .hg/<filename> file
56 """write all the state data stored to .hg/<filename> file
56
57
57 we use third-party library cbor to serialize data to write in the file.
58 we use third-party library cbor to serialize data to write in the file.
58 """
59 """
60 if not isinstance(version, int):
61 raise error.ProgrammingError("version of state file should be"
62 " an integer")
63
59 with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp:
64 with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp:
65 fp.write('%d\n' % iv)
60 cbor.dump(self.opts, fp, canonical=True)
66 cbor.dump(self.opts, fp, canonical=True)
61
67
62 def _read(self):
68 def _read(self):
63 """reads the state file and returns a dictionary which contain
69 """reads the state file and returns a dictionary which contain
64 data in the same format as it was before storing"""
70 data in the same format as it was before storing"""
65 with self._repo.vfs(self.fname, 'rb') as fp:
71 with self._repo.vfs(self.fname, 'rb') as fp:
72 try:
73 version = int(fp.readline())
74 except ValueError:
75 raise error.ProgrammingError("unknown version of state file"
76 " found")
66 return cbor.load(fp)
77 return cbor.load(fp)
67
78
68 def delete(self):
79 def delete(self):
General Comments 0
You need to be logged in to leave comments. Login now