##// END OF EJS Templates
shelve: refactor shelvestate loading...
Kostia Balytskyi -
r32284:16d424b9 default
parent child Browse files
Show More
@@ -176,39 +176,47 class shelvedstate(object):
176 176
177 177 @classmethod
178 178 def load(cls, repo):
179 # Order is important, because old shelvestate file uses it
180 # to detemine values of fields (i.g. version is on the first line,
181 # name is on the second and so forth). Please do not change.
182 keys = ['version', 'name', 'originalwctx', 'pendingctx', 'parents',
183 'nodestoremove', 'branchtorestore', 'keep', 'activebook']
184 d = {}
179 185 fp = repo.vfs(cls._filename)
180 186 try:
181 version = int(fp.readline().strip())
182
183 if version != cls._version:
184 raise error.Abort(_('this version of shelve is incompatible '
185 'with the version used in this repo'))
186 name = fp.readline().strip()
187 wctx = nodemod.bin(fp.readline().strip())
188 pendingctx = nodemod.bin(fp.readline().strip())
189 parents = [nodemod.bin(h) for h in fp.readline().split()]
190 nodestoremove = [nodemod.bin(h) for h in fp.readline().split()]
191 branchtorestore = fp.readline().strip()
192 keep = fp.readline().strip() == cls._keep
193 activebook = fp.readline().strip()
194 except (ValueError, TypeError) as err:
195 raise error.CorruptedState(str(err))
187 for key in keys:
188 d[key] = fp.readline().strip()
196 189 finally:
197 190 fp.close()
198 191
192 # some basic syntactic verification and transformation
193 try:
194 d['version'] = int(d['version'])
195 if d['version'] != cls._version:
196 raise error.Abort(_('this version of shelve is incompatible '
197 'with the version used in this repo'))
198 d['originalwctx'] = nodemod.bin(d['originalwctx'])
199 d['pendingctx'] = nodemod.bin(d['pendingctx'])
200 d['parents'] = [nodemod.bin(h)
201 for h in d['parents'].split(' ')]
202 d['nodestoremove'] = [nodemod.bin(h)
203 for h in d['nodestoremove'].split(' ')]
204 except (ValueError, TypeError, KeyError) as err:
205 raise error.CorruptedState(str(err))
206
199 207 try:
200 208 obj = cls()
201 obj.name = name
202 obj.wctx = repo[wctx]
203 obj.pendingctx = repo[pendingctx]
204 obj.parents = parents
205 obj.nodestoremove = nodestoremove
206 obj.branchtorestore = branchtorestore
207 obj.keep = keep
209 obj.name = d['name']
210 obj.wctx = repo[d['originalwctx']]
211 obj.pendingctx = repo[d['pendingctx']]
212 obj.parents = d['parents']
213 obj.nodestoremove = d['nodestoremove']
214 obj.branchtorestore = d.get('branchtorestore', '')
215 obj.keep = d.get('keep') == cls._keep
208 216 obj.activebookmark = ''
209 if activebook != cls._noactivebook:
210 obj.activebookmark = activebook
211 except error.RepoLookupError as err:
217 if d.get('activebook', '') != cls._noactivebook:
218 obj.activebookmark = d.get('activebook', '')
219 except (error.RepoLookupError, KeyError) as err:
212 220 raise error.CorruptedState(str(err))
213 221
214 222 return obj
General Comments 0
You need to be logged in to leave comments. Login now