hgext3rd/evolve/state.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 23 Jan 2019 15:49:44 -0500
changeset 4368 acfd2b1a6176
parent 4054 46cd437fd3d2
child 4504 4d8db57e24fc
permissions -rw-r--r--
branching: merge with stable A new version has been released
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     1
# This software may be used and distributed according to the terms of the
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     2
# GNU General Public License version 2 or any later version.
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     3
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     4
"""
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3391
diff changeset
     5
This file contains class to wrap the state for commands and other
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     6
related logic.
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     7
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     8
All the data related to the command state is stored as dictionary in the object.
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3391
diff changeset
     9
The class has methods using which the data can be stored to disk in a file under
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3391
diff changeset
    10
.hg/ directory.
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    11
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    12
We store the data on disk in cbor, for which we use cbor library to serialize
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    13
and deserialize data.
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    14
"""
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    15
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    16
from __future__ import absolute_import
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    17
3497
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    18
import errno
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    19
import struct
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    20
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    21
from .thirdparty import cbor
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    22
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    23
from mercurial import (
3497
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    24
    error,
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    25
    util,
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    26
)
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    27
3497
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    28
from mercurial.i18n import _
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    29
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3391
diff changeset
    30
class cmdstate():
4054
46cd437fd3d2 pick: fix last references of grab in code
Boris Feld <boris.feld@octobus.net>
parents: 3874
diff changeset
    31
    """a wrapper class to store the state of commands like `evolve`, `pick`
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    32
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    33
    All the data for the state is stored in the form of key-value pairs in a
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    34
    dictionary.
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    35
3457
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3391
diff changeset
    36
    The class object can write all the data to a file in .hg/ directory and also
82e9f9603b1b evolvestate: rename the file to state.py and class name to cmdstate
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3391
diff changeset
    37
    can populate the object data reading that file
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    38
    """
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    39
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    40
    def __init__(self, repo, path='evolvestate', opts={}):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    41
        self._repo = repo
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    42
        self.path = path
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    43
        self.opts = opts
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    44
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    45
    def __nonzero__(self):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    46
        return self.exists()
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    47
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    48
    def __getitem__(self, key):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    49
        return self.opts[key]
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    50
3874
830a2597ba26 state: add the get() method that evolvecmd:1836 expects
Martin von Zweigbergk <martinvonz@google.com>
parents: 3572
diff changeset
    51
    def get(self, key, default=None):
830a2597ba26 state: add the get() method that evolvecmd:1836 expects
Martin von Zweigbergk <martinvonz@google.com>
parents: 3572
diff changeset
    52
        return self.opts.get(key, default)
830a2597ba26 state: add the get() method that evolvecmd:1836 expects
Martin von Zweigbergk <martinvonz@google.com>
parents: 3572
diff changeset
    53
3572
7934e9751d69 state: add __setitem__() for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3498
diff changeset
    54
    def __setitem__(self, key, value):
7934e9751d69 state: add __setitem__() for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3498
diff changeset
    55
        updates = {key: value}
7934e9751d69 state: add __setitem__() for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3498
diff changeset
    56
        self.opts.update(updates)
7934e9751d69 state: add __setitem__() for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3498
diff changeset
    57
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    58
    def load(self):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    59
        """load the existing evolvestate file into the class object"""
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    60
        op = self._read()
3498
152daa6967af evolve: add comptability to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3497
diff changeset
    61
        if isinstance(op, dict):
152daa6967af evolve: add comptability to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3497
diff changeset
    62
            self.opts.update(op)
152daa6967af evolve: add comptability to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3497
diff changeset
    63
        elif self.path == 'evolvestate':
152daa6967af evolve: add comptability to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3497
diff changeset
    64
            # it is the old evolvestate file
152daa6967af evolve: add comptability to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3497
diff changeset
    65
            oldop = _oldevolvestateread(self._repo)
152daa6967af evolve: add comptability to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3497
diff changeset
    66
            self.opts.update(oldop)
3391
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    67
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    68
    def addopts(self, opts):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    69
        """add more key-value pairs to the data stored by the object"""
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    70
        self.opts.update(opts)
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    71
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    72
    def save(self):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    73
        """write all the evolvestate data stored in .hg/evolvestate file
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    74
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    75
        we use third-party library cbor to serialize data to write in the file.
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    76
        """
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    77
        with self._repo.vfs(self.path, 'wb', atomictemp=True) as fp:
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    78
            cbor.dump(self.opts, fp)
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    79
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    80
    def _read(self):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    81
        """reads the evolvestate file and returns a dictionary which contain
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    82
        data in the same format as it was before storing"""
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    83
        with self._repo.vfs(self.path, 'rb') as fp:
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    84
            return cbor.load(fp)
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    85
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    86
    def delete(self):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    87
        """drop the evolvestate file if exists"""
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    88
        util.unlinkpath(self._repo.vfs.join(self.path), ignoremissing=True)
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    89
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    90
    def exists(self):
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    91
        """check whether the evolvestate file exists or not"""
d2fc2c2783f8 evolvestate: add a class to wrap the state of `hg evolve` command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    92
        return self._repo.vfs.exists(self.path)
3497
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    93
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    94
def _oldevolvestateread(repo):
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    95
    """function to read the old evolvestate file
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    96
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    97
    This exists for BC reasons."""
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    98
    try:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
    99
        f = repo.vfs('evolvestate')
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   100
    except IOError as err:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   101
        if err.errno != errno.ENOENT:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   102
            raise
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   103
    try:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   104
        versionblob = f.read(4)
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   105
        if len(versionblob) < 4:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   106
            repo.ui.debug('ignoring corrupted evolvestate (file contains %i bits)'
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   107
                          % len(versionblob))
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   108
            return None
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   109
        version = struct._unpack('>I', versionblob)[0]
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   110
        if version != 0:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   111
            msg = _('unknown evolvestate version %i') % version
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   112
            raise error.Abort(msg, hint=_('upgrade your evolve'))
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   113
        records = []
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   114
        data = f.read()
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   115
        off = 0
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   116
        end = len(data)
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   117
        while off < end:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   118
            rtype = data[off]
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   119
            off += 1
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   120
            length = struct._unpack('>I', data[off:(off + 4)])[0]
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   121
            off += 4
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   122
            record = data[off:(off + length)]
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   123
            off += length
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   124
            if rtype == 't':
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   125
                rtype, record = record[0], record[1:]
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   126
            records.append((rtype, record))
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   127
        state = {}
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   128
        for rtype, rdata in records:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   129
            if rtype == 'C':
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   130
                state['current'] = rdata
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   131
            elif rtype.lower():
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   132
                repo.ui.debug('ignore evolve state record type %s' % rtype)
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   133
            else:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   134
                raise error.Abort(_('unknown evolvestate field type %r')
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   135
                                  % rtype, hint=_('upgrade your evolve'))
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   136
        return state
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   137
    finally:
dae819761c0e state: bring back the function to read old evolvestate files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3457
diff changeset
   138
        f.close()