Mercurial > hg
comparison hgext/histedit.py @ 38505:c6a2ce82e60b
histedit: factor out logic of processing state data in separate fn
The new function will serve as the point from where we always get a dictionary
of data stored in the statefile and will be helpful in integrating
state.cmdstate.read() to write statefile in cbor.
Differential Revision: https://phab.mercurial-scm.org/D3863
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 30 Jun 2018 07:10:49 +0530 |
parents | 3beb0ea083df |
children | 18f348e035fb |
comparison
equal
deleted
inserted
replaced
38504:3beb0ea083df | 38505:c6a2ce82e60b |
---|---|
316 except IOError as err: | 316 except IOError as err: |
317 if err.errno != errno.ENOENT: | 317 if err.errno != errno.ENOENT: |
318 raise | 318 raise |
319 cmdutil.wrongtooltocontinue(self.repo, _('histedit')) | 319 cmdutil.wrongtooltocontinue(self.repo, _('histedit')) |
320 | 320 |
321 if state.startswith('v1\n'): | 321 data = self._read(state) |
322 | |
323 self.parentctxnode = data['parentctxnode'] | |
324 actions = parserules(data['rules'], self) | |
325 self.actions = actions | |
326 self.keep = data['keep'] | |
327 self.topmost = data['topmost'] | |
328 self.replacements = data['replacements'] | |
329 self.backupfile = data['backupfile'] | |
330 | |
331 def _read(self, fp): | |
332 if fp.startswith('v1\n'): | |
322 data = self._load() | 333 data = self._load() |
323 parentctxnode, rules, keep, topmost, replacements, backupfile = data | 334 parentctxnode, rules, keep, topmost, replacements, backupfile = data |
324 else: | 335 else: |
325 data = pickle.loads(state) | 336 data = pickle.loads(fp) |
326 parentctxnode, rules, keep, topmost, replacements = data | 337 parentctxnode, rules, keep, topmost, replacements = data |
327 backupfile = None | 338 backupfile = None |
328 | |
329 self.parentctxnode = parentctxnode | |
330 rules = "\n".join(["%s %s" % (verb, rest) for [verb, rest] in rules]) | 339 rules = "\n".join(["%s %s" % (verb, rest) for [verb, rest] in rules]) |
331 actions = parserules(rules, self) | 340 |
332 self.actions = actions | 341 return {'parentctxnode': parentctxnode, "rules": rules, "keep": keep, |
333 self.keep = keep | 342 "topmost": topmost, "replacements": replacements, |
334 self.topmost = topmost | 343 "backupfile": backupfile} |
335 self.replacements = replacements | |
336 self.backupfile = backupfile | |
337 | 344 |
338 def write(self, tr=None): | 345 def write(self, tr=None): |
339 if tr: | 346 if tr: |
340 tr.addfilegenerator('histedit-state', ('histedit-state',), | 347 tr.addfilegenerator('histedit-state', ('histedit-state',), |
341 self._write, location='plain') | 348 self._write, location='plain') |