# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1517304760 -19800 # Node ID dae819761c0e2379a8f174d52e02be1da96b4d06 # Parent af2602c354d8a125fffa2f3acd449726fdadfc3d state: bring back the function to read old evolvestate files Before introduction of this nice cmdstate file wrapper, we had individual methods to write data to evolvestate file. Let's bring back the function which used to read data from the old evolvestae file so that we can use it in next patch for BC purposes. diff -r af2602c354d8 -r dae819761c0e hgext3rd/evolve/state.py --- a/hgext3rd/evolve/state.py Tue Jan 30 00:02:29 2018 +0530 +++ b/hgext3rd/evolve/state.py Tue Jan 30 15:02:40 2018 +0530 @@ -15,12 +15,18 @@ from __future__ import absolute_import +import errno +import struct + from .thirdparty import cbor from mercurial import ( + error, util, ) +from mercurial.i18n import _ + class cmdstate(): """a wrapper class to store the state of commands like `evolve`, `grab` @@ -72,3 +78,49 @@ def exists(self): """check whether the evolvestate file exists or not""" return self._repo.vfs.exists(self.path) + +def _oldevolvestateread(repo): + """function to read the old evolvestate file + + This exists for BC reasons.""" + try: + f = repo.vfs('evolvestate') + except IOError as err: + if err.errno != errno.ENOENT: + raise + try: + versionblob = f.read(4) + if len(versionblob) < 4: + repo.ui.debug('ignoring corrupted evolvestate (file contains %i bits)' + % len(versionblob)) + return None + version = struct._unpack('>I', versionblob)[0] + if version != 0: + msg = _('unknown evolvestate version %i') % version + raise error.Abort(msg, hint=_('upgrade your evolve')) + records = [] + data = f.read() + off = 0 + end = len(data) + while off < end: + rtype = data[off] + off += 1 + length = struct._unpack('>I', data[off:(off + 4)])[0] + off += 4 + record = data[off:(off + length)] + off += length + if rtype == 't': + rtype, record = record[0], record[1:] + records.append((rtype, record)) + state = {} + for rtype, rdata in records: + if rtype == 'C': + state['current'] = rdata + elif rtype.lower(): + repo.ui.debug('ignore evolve state record type %s' % rtype) + else: + raise error.Abort(_('unknown evolvestate field type %r') + % rtype, hint=_('upgrade your evolve')) + return state + finally: + f.close()