mercurial/state.py
author Taapas Agrawal <taapas2897@gmail.com>
Sun, 09 Jun 2019 00:43:36 +0530
changeset 42537 dc3fdd1b5af4
parent 42536 5f2f6912c9e6
child 42538 5bddd2244814
permissions -rw-r--r--
state: created new class statecheck to handle unfinishedstates For the purpose of handling states for various multistep operations like `hg graft`, `hg histedit`, `hg bisect` et al a new class called statecheck is created .This will help in having a unified approach towards these commands and handle them with ease. The class takes in 4 basic arguments which include the name of the command, the name of the state file associated with it , clearable flag , allowcommit flag. This also also adds the support of`checkunfinished()` and `clearunfinished()` to the class. Tests remain unchanged. Differential Revision: https://phab.mercurial-scm.org/D6501
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     1
# state.py - writing and reading state files in Mercurial
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     2
#
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     3
# Copyright 2018 Pulkit Goyal <pulkitmgoyal@gmail.com>
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     4
#
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     7
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     8
"""
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     9
This file contains class to wrap the state for commands and other
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    10
related logic.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    11
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    12
All the data related to the command state is stored as dictionary in the object.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    13
The class has methods using which the data can be stored to disk in a file under
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    14
.hg/ directory.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    15
41136
050ea8eb42a5 state: update comment about use of CBOR
Augie Fackler <augie@google.com>
parents: 39470
diff changeset
    16
We store the data on disk in cbor, for which we use the CBOR format to encode
050ea8eb42a5 state: update comment about use of CBOR
Augie Fackler <augie@google.com>
parents: 39470
diff changeset
    17
the data.
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    18
"""
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    19
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    20
from __future__ import absolute_import
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    21
42536
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 41136
diff changeset
    22
from .i18n import _
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 41136
diff changeset
    23
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    24
from . import (
38139
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    25
    error,
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    26
    util,
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    27
)
39470
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38178
diff changeset
    28
from .utils import (
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38178
diff changeset
    29
    cborutil,
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38178
diff changeset
    30
)
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    31
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    32
class cmdstate(object):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    33
    """a wrapper class to store the state of commands like `rebase`, `graft`,
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    34
    `histedit`, `shelve` etc. Extensions can also use this to write state files.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    35
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    36
    All the data for the state is stored in the form of key-value pairs in a
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    37
    dictionary.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    38
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    39
    The class object can write all the data to a file in .hg/ directory and
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    40
    can populate the object data reading that file.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    41
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    42
    Uses cbor to serialize and deserialize data while writing and reading from
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    43
    disk.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    44
    """
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    45
38178
6f67bfe4b82f state: removing remaining instances of opts class variable
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38166
diff changeset
    46
    def __init__(self, repo, fname):
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    47
        """ repo is the repo object
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    48
        fname is the file name in which data should be stored in .hg directory
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    49
        """
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    50
        self._repo = repo
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    51
        self.fname = fname
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    52
38137
36a5a1239a15 state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38136
diff changeset
    53
    def read(self):
36a5a1239a15 state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38136
diff changeset
    54
        """read the existing state file and return a dict of data stored"""
36a5a1239a15 state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38136
diff changeset
    55
        return self._read()
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    56
38139
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    57
    def save(self, version, data):
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    58
        """write all the state data stored to .hg/<filename> file
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    59
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    60
        we use third-party library cbor to serialize data to write in the file.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    61
        """
38139
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    62
        if not isinstance(version, int):
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    63
            raise error.ProgrammingError("version of state file should be"
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    64
                                         " an integer")
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    65
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    66
        with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp:
38159
bdc4079ceb16 state: fix usage of an unassigned variable
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38139
diff changeset
    67
            fp.write('%d\n' % version)
39470
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38178
diff changeset
    68
            for chunk in cborutil.streamencode(data):
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38178
diff changeset
    69
                fp.write(chunk)
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    70
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    71
    def _read(self):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    72
        """reads the state file and returns a dictionary which contain
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    73
        data in the same format as it was before storing"""
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    74
        with self._repo.vfs(self.fname, 'rb') as fp:
38139
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    75
            try:
38160
b7e5c53a779e state: temporary silence pyflakes warning by removing variable assignment
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38159
diff changeset
    76
                int(fp.readline())
38139
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38138
diff changeset
    77
            except ValueError:
38166
dce718404ce6 state: raise CorruptedState error isntead of ProgrammingError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38160
diff changeset
    78
                raise error.CorruptedState("unknown version of state file"
dce718404ce6 state: raise CorruptedState error isntead of ProgrammingError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38160
diff changeset
    79
                                           " found")
39470
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38178
diff changeset
    80
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38178
diff changeset
    81
            return cborutil.decodeall(fp.read())[0]
38136
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    82
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    83
    def delete(self):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    84
        """drop the state file if exists"""
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    85
        util.unlinkpath(self._repo.vfs.join(self.fname), ignoremissing=True)
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    86
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    87
    def exists(self):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    88
        """check whether the state file exists or not"""
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    89
        return self._repo.vfs.exists(self.fname)
42536
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 41136
diff changeset
    90
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    91
class _statecheck(object):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    92
    """a utility class that deals with multistep operations like graft,
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    93
       histedit, bisect, update etc and check whether such commands
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    94
       are in an unfinished conditition or not and return appropriate message
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    95
       and hint.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    96
       It also has the ability to register and determine the states of any new
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    97
       multistep operation or multistep command extension.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    98
    """
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
    99
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   100
    def __init__(self, opname, fname, clearable=False, allowcommit=False,
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   101
                 cmdmsg="", cmdhint=""):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   102
        """opname is the name the command or operation
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   103
        fname is the file name in which data should be stored in .hg directory.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   104
        It is None for merge command.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   105
        clearable boolean determines whether or not interrupted states can be
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   106
        cleared by running `hg update -C .` which in turn deletes the
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   107
        state file.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   108
        allowcommit boolean decides whether commit is allowed during interrupted
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   109
        state or not.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   110
        cmdmsg is used to pass a different status message in case standard
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   111
        message of the format "abort: cmdname in progress" is not desired.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   112
        cmdhint is used to pass a different hint message in case standard
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   113
        message of the format use 'hg cmdname --continue' or
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   114
        'hg cmdname --abort'" is not desired.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   115
        """
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   116
        self._opname = opname
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   117
        self._fname = fname
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   118
        self._clearable = clearable
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   119
        self._allowcommit = allowcommit
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   120
        self._cmdhint = cmdhint
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   121
        self._cmdmsg = cmdmsg
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   122
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   123
    def hint(self):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   124
        """returns the hint message corresponding to the command"""
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   125
        if not self._cmdhint:
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   126
                return (_("use 'hg %s --continue' or 'hg %s --abort'") %
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   127
                        (self._opname, self._opname))
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   128
        return self._cmdhint
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   129
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   130
    def msg(self):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   131
        """returns the status message corresponding to the command"""
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   132
        if not self._cmdmsg:
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   133
            return _('%s in progress') % (self._opname)
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   134
        return self._cmdmsg
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   135
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   136
    def isunfinished(self, repo):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   137
        """determines whether a multi-step operation is in progress or not"""
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   138
        return repo.vfs.exists(self._fname)
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   139
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   140
# A list of statecheck objects for multistep operations like graft.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   141
_unfinishedstates = []
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   142
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   143
def addunfinished(opname, **kwargs):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   144
    """this registers a new command or operation to unfinishedstates
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   145
    """
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   146
    statecheckobj = _statecheck(opname, **kwargs)
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   147
    _unfinishedstates.append(statecheckobj)
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   148
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   149
addunfinished(
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   150
    'graft', fname='graftstate', clearable=True,
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   151
    cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop")
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   152
)
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   153
addunfinished(
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   154
    'update', fname='updatestate', clearable=True,
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   155
    cmdmsg=_('last update was interrupted'),
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   156
    cmdhint=_("use 'hg update' to get a consistent checkout")
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
   157
)