comparison hgext/histedit.py @ 38507:03e7ec8180f0

histedit: use self.stateobj to check whether interrupted histedit exists self.stateobj is an instance of state.cmdstate() class which has an .exists() function which is used to check whether there exists an interrupted statefile or not. Differential Revision: https://phab.mercurial-scm.org/D3865
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 30 Jun 2018 07:23:02 +0530
parents 18f348e035fb
children 39db5a01cd53
comparison
equal deleted inserted replaced
38506:18f348e035fb 38507:03e7ec8180f0
181 181
182 """ 182 """
183 183
184 from __future__ import absolute_import 184 from __future__ import absolute_import
185 185
186 import errno
187 import os 186 import os
188 187
189 from mercurial.i18n import _ 188 from mercurial.i18n import _
190 from mercurial import ( 189 from mercurial import (
191 bundle2, 190 bundle2,
311 else: 310 else:
312 self.replacements = replacements 311 self.replacements = replacements
313 312
314 def read(self): 313 def read(self):
315 """Load histedit state from disk and set fields appropriately.""" 314 """Load histedit state from disk and set fields appropriately."""
316 try: 315 if not self.stateobj.exists():
317 state = self.repo.vfs.read('histedit-state')
318 except IOError as err:
319 if err.errno != errno.ENOENT:
320 raise
321 cmdutil.wrongtooltocontinue(self.repo, _('histedit')) 316 cmdutil.wrongtooltocontinue(self.repo, _('histedit'))
322 317
323 data = self._read(state) 318 data = self._read()
324 319
325 self.parentctxnode = data['parentctxnode'] 320 self.parentctxnode = data['parentctxnode']
326 actions = parserules(data['rules'], self) 321 actions = parserules(data['rules'], self)
327 self.actions = actions 322 self.actions = actions
328 self.keep = data['keep'] 323 self.keep = data['keep']
329 self.topmost = data['topmost'] 324 self.topmost = data['topmost']
330 self.replacements = data['replacements'] 325 self.replacements = data['replacements']
331 self.backupfile = data['backupfile'] 326 self.backupfile = data['backupfile']
332 327
333 def _read(self, fp): 328 def _read(self):
329 fp = self.repo.vfs.read('histedit-state')
334 if fp.startswith('v1\n'): 330 if fp.startswith('v1\n'):
335 data = self._load() 331 data = self._load()
336 parentctxnode, rules, keep, topmost, replacements, backupfile = data 332 parentctxnode, rules, keep, topmost, replacements, backupfile = data
337 else: 333 else:
338 data = pickle.loads(fp) 334 data = pickle.loads(fp)