mercurial/state.py
author Augie Fackler <augie@google.com>
Fri, 26 Jun 2020 11:20:58 -0400
changeset 45005 05277278f177
parent 43773 7b14d649af1b
child 45171 5322e738be0f
permissions -rw-r--r--
merge with stable
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,
43773
7b14d649af1b typing: consolidate "if not globals():" trick
Yuya Nishihara <yuya@tcha.org>
parents: 43702
diff changeset
    26
    pycompat,
38103
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    27
    util,
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    28
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
    29
from .utils import cborutil
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
    30
43773
7b14d649af1b typing: consolidate "if not globals():" trick
Yuya Nishihara <yuya@tcha.org>
parents: 43702
diff changeset
    31
if pycompat.TYPE_CHECKING:
43702
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    32
    from typing import (
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    33
        Any,
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    34
        Dict,
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    35
    )
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    36
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    37
    for t in (Any, Dict):
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    38
        assert t
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    39
38103
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    40
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    41
class cmdstate(object):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    42
    """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
    43
    `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
    44
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    45
    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
    46
    dictionary.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    47
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    48
    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
    49
    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
    50
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    51
    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
    52
    disk.
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    53
    """
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    54
38145
6f67bfe4b82f state: removing remaining instances of opts class variable
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38133
diff changeset
    55
    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
    56
        """ 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
    57
        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
    58
        """
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    59
        self._repo = repo
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    60
        self.fname = fname
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    61
38104
36a5a1239a15 state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38103
diff changeset
    62
    def read(self):
43702
127d46468a45 state: add a pytype annotation
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    63
        # type: () -> Dict[bytes, Any]
38104
36a5a1239a15 state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38103
diff changeset
    64
        """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
    65
        return self._read()
38103
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    66
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
diff changeset
    67
    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
    68
        """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
    69
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    70
        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
    71
        """
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
diff changeset
    72
        if not isinstance(version, int):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
    73
            raise error.ProgrammingError(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
    74
                b"version of state file should be an integer"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
    75
            )
38106
a0e4d654bceb state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38105
diff changeset
    76
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    77
        with self._repo.vfs(self.fname, b'wb', atomictemp=True) as fp:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    78
            fp.write(b'%d\n' % version)
39451
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    79
            for chunk in cborutil.streamencode(data):
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    80
                fp.write(chunk)
38103
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    81
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    82
    def _read(self):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    83
        """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
    84
        data in the same format as it was before storing"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    85
        with self._repo.vfs(self.fname, b'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
    86
            try:
38127
b7e5c53a779e state: temporary silence pyflakes warning by removing variable assignment
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38126
diff changeset
    87
                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
    88
            except ValueError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
    89
                raise error.CorruptedState(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
    90
                    b"unknown version of state file found"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
    91
                )
39451
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    92
5bfab9400daf state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38145
diff changeset
    93
            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
    94
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    95
    def delete(self):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    96
        """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
    97
        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
    98
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    99
    def exists(self):
a2f83661f721 state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   100
        """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
   101
        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
   102
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   103
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   104
class _statecheck(object):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   105
    """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
   106
       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
   107
       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
   108
       and hint.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   109
       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
   110
       multistep operation or multistep command extension.
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   111
    """
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   112
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   113
    def __init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   114
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   115
        opname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   116
        fname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   117
        clearable,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   118
        allowcommit,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   119
        reportonly,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   120
        continueflag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   121
        stopflag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   122
        cmdmsg,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   123
        cmdhint,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   124
        statushint,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   125
        abortfunc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   126
        continuefunc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   127
    ):
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   128
        self._opname = opname
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   129
        self._fname = fname
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   130
        self._clearable = clearable
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   131
        self._allowcommit = allowcommit
42534
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   132
        self._reportonly = reportonly
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   133
        self._continueflag = continueflag
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   134
        self._stopflag = stopflag
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   135
        self._cmdmsg = cmdmsg
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   136
        self._cmdhint = cmdhint
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   137
        self._statushint = statushint
42581
bb135a784b70 abort: added logic for of hg abort
Taapas Agrawal <taapas2897@gmail.com>
parents: 42541
diff changeset
   138
        self.abortfunc = abortfunc
42612
3c16b9c0b099 continue: added logic for hg continue
Taapas Agrawal <taapas2897@gmail.com>
parents: 42600
diff changeset
   139
        self.continuefunc = continuefunc
42532
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
    def statusmsg(self):
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   142
        """returns the hint message corresponding to the command for
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   143
        hg status --verbose
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   144
        """
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   145
        if not self._statushint:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   146
            hint = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   147
                b'To continue:    hg %s --continue\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   148
                b'To abort:       hg %s --abort'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   149
            ) % (self._opname, self._opname)
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   150
            if self._stopflag:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   151
                hint = hint + (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   152
                    _(b'\nTo stop:        hg %s --stop') % (self._opname)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   153
                )
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   154
            return hint
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   155
        return self._statushint
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   156
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   157
    def hint(self):
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   158
        """returns the hint message corresponding to an interrupted
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   159
        operation
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   160
        """
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   161
        if not self._cmdhint:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   162
            return _(b"use 'hg %s --continue' or 'hg %s --abort'") % (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   163
                self._opname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   164
                self._opname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   165
            )
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   166
        return self._cmdhint
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   167
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   168
    def msg(self):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   169
        """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
   170
        if not self._cmdmsg:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   171
            return _(b'%s in progress') % (self._opname)
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   172
        return self._cmdmsg
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   173
42533
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   174
    def continuemsg(self):
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   175
        """ returns appropriate continue message corresponding to command"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   176
        return _(b'hg %s --continue') % (self._opname)
42533
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42532
diff changeset
   177
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   178
    def isunfinished(self, repo):
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   179
        """determines whether a multi-step operation is in progress
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   180
        or not
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   181
        """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   182
        if self._opname == b'merge':
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   183
            return len(repo[None].parents()) > 1
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   184
        else:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   185
            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
   186
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   187
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   188
# 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
   189
_unfinishedstates = []
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   190
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   191
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   192
def addunfinished(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   193
    opname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   194
    fname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   195
    clearable=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   196
    allowcommit=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   197
    reportonly=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   198
    continueflag=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   199
    stopflag=False,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   200
    cmdmsg=b"",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   201
    cmdhint=b"",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   202
    statushint=b"",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   203
    abortfunc=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   204
    continuefunc=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   205
):
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   206
    """this registers a new command or operation to unfinishedstates
42534
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   207
    opname is the name the command or operation
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   208
    fname is the file name in which data should be stored in .hg directory.
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   209
    It is None for merge command.
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   210
    clearable boolean determines whether or not interrupted states can be
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   211
    cleared by running `hg update -C .` which in turn deletes the
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   212
    state file.
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   213
    allowcommit boolean decides whether commit is allowed during interrupted
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   214
    state or not.
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   215
    reportonly flag is used for operations like bisect where we just
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   216
    need to detect the operation using 'hg status --verbose'
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   217
    continueflag is a boolean determines whether or not a command supports
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   218
    `--continue` option or not.
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   219
    stopflag is a boolean that determines whether or not a command supports
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   220
    --stop flag
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   221
    cmdmsg is used to pass a different status message in case standard
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   222
    message of the format "abort: cmdname in progress" is not desired.
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   223
    cmdhint is used to pass a different hint message in case standard
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   224
    message of the format "To continue: hg cmdname --continue
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   225
    To abort: hg cmdname --abort" is not desired.
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   226
    statushint is used to pass a different status message in case standard
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   227
    message of the format ('To continue:    hg cmdname --continue'
faec09d89435 statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents: 42533
diff changeset
   228
    'To abort:       hg cmdname --abort') is not desired
42581
bb135a784b70 abort: added logic for of hg abort
Taapas Agrawal <taapas2897@gmail.com>
parents: 42541
diff changeset
   229
    abortfunc stores the function required to abort an unfinished state.
42612
3c16b9c0b099 continue: added logic for hg continue
Taapas Agrawal <taapas2897@gmail.com>
parents: 42600
diff changeset
   230
    continuefunc stores the function required to finish an interrupted
3c16b9c0b099 continue: added logic for hg continue
Taapas Agrawal <taapas2897@gmail.com>
parents: 42600
diff changeset
   231
    operation.
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   232
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   233
    statecheckobj = _statecheck(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   234
        opname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   235
        fname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   236
        clearable,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   237
        allowcommit,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   238
        reportonly,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   239
        continueflag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   240
        stopflag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   241
        cmdmsg,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   242
        cmdhint,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   243
        statushint,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   244
        abortfunc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   245
        continuefunc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   246
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   247
    if opname == b'merge':
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   248
        _unfinishedstates.append(statecheckobj)
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   249
    else:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   250
        _unfinishedstates.insert(0, statecheckobj)
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   251
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   252
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   253
addunfinished(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   254
    b'update',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   255
    fname=b'updatestate',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   256
    clearable=True,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   257
    cmdmsg=_(b'last update was interrupted'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   258
    cmdhint=_(b"use 'hg update' to get a consistent checkout"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   259
    statushint=_(b"To continue:    hg update ."),
42530
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42529
diff changeset
   260
)
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   261
addunfinished(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   262
    b'bisect',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   263
    fname=b'bisect.state',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   264
    allowcommit=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   265
    reportonly=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   266
    statushint=_(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   267
        b'To mark the changeset good:    hg bisect --good\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   268
        b'To mark the changeset bad:     hg bisect --bad\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   269
        b'To abort:                      hg bisect --reset\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   270
    ),
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   271
)
42531
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   272
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43045
diff changeset
   273
42531
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   274
def getrepostate(repo):
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42530
diff changeset
   275
    # experimental config: commands.status.skipstates
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   276
    skip = set(repo.ui.configlist(b'commands', b'status.skipstates'))
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   277
    for state in _unfinishedstates:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   278
        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
   279
            continue
42532
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   280
        if state.isunfinished(repo):
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42531
diff changeset
   281
            return (state._opname, state.statusmsg())