mercurial/state.py
author Taapas Agrawal <taapas2897@gmail.com>
Thu, 20 Jun 2019 11:40:08 +0530
changeset 42533 0231032729c4
parent 42532 12243f15d53e
child 42534 faec09d89435
permissions -rw-r--r--
statecheck: added support for cmdutil.afterresolvedstates This removes `afterresolvedstates` from `cmdutil` and adds support for it in `_statecheck` class. A new flag `continueflag` is added to the class to check whether an operation supports `--continue` option or not. Tests remain unchanged. Differential Revision: https://phab.mercurial-scm.org/D6551
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38103
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
41135
050ea8eb42a5 state: update comment about use of CBOR
Augie Fackler <augie@google.com>
parents: 39451
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: 39451
diff changeset
    17
the data.
38103
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
42529
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 41135
diff changeset
    22
from .i18n import _
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 41135
diff changeset
    23
38103
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    24
from . import (
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
diff changeset
    25
    error,
38103
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
)
39451
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    28
from .utils import (
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    29
    cborutil,
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    30
)
38103
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
38145
6f67bfe4b82f state: removing remaining instances of opts class variable
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38133
diff changeset
    46
    def __init__(self, repo, fname):
38103
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
38104
36a5a1239a15 state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38103
diff changeset
    53
    def read(self):
36a5a1239a15 state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38103
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: 38103
diff changeset
    55
        return self._read()
38103
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    56
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
diff changeset
    57
    def save(self, version, data):
38103
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
        """
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
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: 38105
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: 38105
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: 38105
diff changeset
    65
38103
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:
38126
bdc4079ceb16 state: fix usage of an unassigned variable
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38106
diff changeset
    67
            fp.write('%d\n' % version)
39451
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    68
            for chunk in cborutil.streamencode(data):
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    69
                fp.write(chunk)
38103
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:
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
diff changeset
    75
            try:
38127
b7e5c53a779e state: temporary silence pyflakes warning by removing variable assignment
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38126
diff changeset
    76
                int(fp.readline())
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
diff changeset
    77
            except ValueError:
38133
dce718404ce6 state: raise CorruptedState error isntead of ProgrammingError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38127
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: 38127
diff changeset
    79
                                           " found")
39451
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    80
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    81
            return cborutil.decodeall(fp.read())[0]
38103
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)
42529
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 41135
diff changeset
    90
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
    91
class _statecheck(object):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
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: 42529
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: 42529
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: 42529
diff changeset
    95
       and hint.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
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: 42529
diff changeset
    97
       multistep operation or multistep command extension.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
    98
    """
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
    99
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   100
    def __init__(self, opname, fname, clearable=False, allowcommit=False,
42533
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   101
                 reportonly=False, continueflag=False, stopflag=False ,
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   102
                 cmdmsg="", cmdhint="", statushint=""):
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   103
        """opname is the name the command or operation
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   104
        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: 42529
diff changeset
   105
        It is None for merge command.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   106
        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: 42529
diff changeset
   107
        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: 42529
diff changeset
   108
        state file.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   109
        allowcommit boolean decides whether commit is allowed during interrupted
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   110
        state or not.
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   111
        reportonly flag is used for operations like bisect where we just
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   112
        need to detect the operation using 'hg status --verbose'
42533
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   113
        continueflag is a boolean determines whether or not a command supports
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   114
        `--continue` option or not.
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   115
        stopflag is a boolean that determines whether or not a command supports
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   116
        --stop flag
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   117
        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: 42529
diff changeset
   118
        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: 42529
diff changeset
   119
        cmdhint is used to pass a different hint message in case standard
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   120
        message of the format "To continue: hg cmdname --continue
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   121
        To abort: hg cmdname --abort" is not desired.
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   122
        statushint is used to pass a different status message in case standard
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   123
        message of the format ('To continue:    hg cmdname --continue'
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   124
        'To abort:       hg cmdname --abort') is not desired
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   125
        """
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   126
        self._opname = opname
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   127
        self._fname = fname
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   128
        self._clearable = clearable
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   129
        self._allowcommit = allowcommit
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   130
        self._cmdhint = cmdhint
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   131
        self._statushint = statushint
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   132
        self._cmdmsg = cmdmsg
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   133
        self._stopflag = stopflag
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   134
        self._reportonly = reportonly
42533
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   135
        self._continueflag = continueflag
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   136
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   137
    def statusmsg(self):
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   138
        """returns the hint message corresponding to the command for
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   139
        hg status --verbose
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   140
        """
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   141
        if not self._statushint:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   142
            hint = (_('To continue:    hg %s --continue\n'
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   143
                      'To abort:       hg %s --abort') % (self._opname,
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   144
                       self._opname))
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   145
            if self._stopflag:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   146
                hint = hint + (_('\nTo stop:        hg %s --stop') %
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   147
                            (self._opname))
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   148
            return hint
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   149
        return self._statushint
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   150
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   151
    def hint(self):
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   152
        """returns the hint message corresponding to an interrupted
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   153
        operation
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   154
        """
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   155
        if not self._cmdhint:
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   156
                return (_("use 'hg %s --continue' or 'hg %s --abort'") %
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   157
                        (self._opname, self._opname))
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   158
        return self._cmdhint
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   159
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   160
    def msg(self):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   161
        """returns the status message corresponding to the command"""
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   162
        if not self._cmdmsg:
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   163
            return _('%s in progress') % (self._opname)
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   164
        return self._cmdmsg
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   165
42533
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   166
    def continuemsg(self):
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   167
        """ returns appropriate continue message corresponding to command"""
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   168
        return _('hg %s --continue') % (self._opname)
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   169
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   170
    def isunfinished(self, repo):
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   171
        """determines whether a multi-step operation is in progress
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   172
        or not
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   173
        """
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   174
        if self._opname == 'merge':
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   175
            return len(repo[None].parents()) > 1
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   176
        else:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   177
            return repo.vfs.exists(self._fname)
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   178
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   179
# 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: 42529
diff changeset
   180
_unfinishedstates = []
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   181
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   182
def addunfinished(opname, **kwargs):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   183
    """this registers a new command or operation to unfinishedstates
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   184
    """
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   185
    statecheckobj = _statecheck(opname, **kwargs)
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   186
    if opname == 'merge':
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   187
        _unfinishedstates.append(statecheckobj)
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   188
    else:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   189
        _unfinishedstates.insert(0, statecheckobj)
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   190
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   191
addunfinished(
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   192
    'graft', fname='graftstate', clearable=True, stopflag=True,
42533
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   193
    continueflag=True,
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   194
    cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop")
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   195
)
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   196
addunfinished(
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   197
    'update', fname='updatestate', clearable=True,
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   198
    cmdmsg=_('last update was interrupted'),
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   199
    cmdhint=_("use 'hg update' to get a consistent checkout"),
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   200
    statushint=_("To continue:    hg update")
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   201
)
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   202
addunfinished(
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   203
    'bisect', fname='bisect.state', allowcommit=True, reportonly=True,
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   204
    statushint=_('To mark the changeset good:    hg bisect --good\n'
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   205
                 'To mark the changeset bad:     hg bisect --bad\n'
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   206
                 'To abort:                      hg bisect --reset\n')
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   207
)
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   208
addunfinished(
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   209
    'merge', fname=None, clearable=True, allowcommit=True,
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   210
    cmdmsg=_('outstanding uncommitted merge'),
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   211
    statushint=_('To continue:    hg commit\n'
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   212
                 'To abort:       hg merge --abort'),
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   213
    cmdhint=_("use 'hg commit' or 'hg merge --abort'")
42531
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   214
)
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   215
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   216
def getrepostate(repo):
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   217
    # experimental config: commands.status.skipstates
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   218
    skip = set(repo.ui.configlist('commands', 'status.skipstates'))
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   219
    for state in _unfinishedstates:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   220
        if state._opname in skip:
42531
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   221
            continue
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   222
        if state.isunfinished(repo):
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   223
            return (state._opname, state.statusmsg())