comparison mercurial/state.py @ 42581:bb135a784b70

abort: added logic for of hg abort This is part of `GSoC19` project `Implement abort and continue commands`. This patch is part of the `abort plan`. This adds the basic logic for `hg abort`. This command aborts an multistep operation like graft, histedit, rebase, merge and unshelve if they are in an unfinished state. The first part of the logic is determining the unfinished operation from the state detection API under `statemod`. This API is extended to support `hg abort` by adding a method to register the abort logic as a function (here `abortfunc`). Once the unfinished operation is determined the registered logic is used to abort the command. The benefit of this kind of framework is that any new extension developed can support `hg abort` by registering the command and logic under statedetection API. `hg abort` currently supports `--dry-run/-n` flag only. It is used to dry run `hg abort` Further patches sequentially add support for `graft`, `rebase`, `unshelve`, `histedit` and `merge`. Differential Revision: https://phab.mercurial-scm.org/D6566
author Taapas Agrawal <taapas2897@gmail.com>
date Sun, 23 Jun 2019 20:58:01 +0530
parents 3de4f17f4824
children 5171937ad0f9
comparison
equal deleted inserted replaced
42580:eb7bd7d64a9d 42581:bb135a784b70
96 It also has the ability to register and determine the states of any new 96 It also has the ability to register and determine the states of any new
97 multistep operation or multistep command extension. 97 multistep operation or multistep command extension.
98 """ 98 """
99 99
100 def __init__(self, opname, fname, clearable, allowcommit, reportonly, 100 def __init__(self, opname, fname, clearable, allowcommit, reportonly,
101 continueflag, stopflag, cmdmsg, cmdhint, statushint): 101 continueflag, stopflag, cmdmsg, cmdhint, statushint,
102 abortfunc):
102 self._opname = opname 103 self._opname = opname
103 self._fname = fname 104 self._fname = fname
104 self._clearable = clearable 105 self._clearable = clearable
105 self._allowcommit = allowcommit 106 self._allowcommit = allowcommit
106 self._reportonly = reportonly 107 self._reportonly = reportonly
107 self._continueflag = continueflag 108 self._continueflag = continueflag
108 self._stopflag = stopflag 109 self._stopflag = stopflag
109 self._cmdmsg = cmdmsg 110 self._cmdmsg = cmdmsg
110 self._cmdhint = cmdhint 111 self._cmdhint = cmdhint
111 self._statushint = statushint 112 self._statushint = statushint
113 self.abortfunc = abortfunc
112 114
113 def statusmsg(self): 115 def statusmsg(self):
114 """returns the hint message corresponding to the command for 116 """returns the hint message corresponding to the command for
115 hg status --verbose 117 hg status --verbose
116 """ 118 """
155 # A list of statecheck objects for multistep operations like graft. 157 # A list of statecheck objects for multistep operations like graft.
156 _unfinishedstates = [] 158 _unfinishedstates = []
157 159
158 def addunfinished(opname, fname, clearable=False, allowcommit=False, 160 def addunfinished(opname, fname, clearable=False, allowcommit=False,
159 reportonly=False, continueflag=False, stopflag=False, 161 reportonly=False, continueflag=False, stopflag=False,
160 cmdmsg="", cmdhint="", statushint=""): 162 cmdmsg="", cmdhint="", statushint="", abortfunc=None):
161 """this registers a new command or operation to unfinishedstates 163 """this registers a new command or operation to unfinishedstates
162 opname is the name the command or operation 164 opname is the name the command or operation
163 fname is the file name in which data should be stored in .hg directory. 165 fname is the file name in which data should be stored in .hg directory.
164 It is None for merge command. 166 It is None for merge command.
165 clearable boolean determines whether or not interrupted states can be 167 clearable boolean determines whether or not interrupted states can be
179 message of the format "To continue: hg cmdname --continue 181 message of the format "To continue: hg cmdname --continue
180 To abort: hg cmdname --abort" is not desired. 182 To abort: hg cmdname --abort" is not desired.
181 statushint is used to pass a different status message in case standard 183 statushint is used to pass a different status message in case standard
182 message of the format ('To continue: hg cmdname --continue' 184 message of the format ('To continue: hg cmdname --continue'
183 'To abort: hg cmdname --abort') is not desired 185 'To abort: hg cmdname --abort') is not desired
186 abortfunc stores the function required to abort an unfinished state.
184 """ 187 """
185 statecheckobj = _statecheck(opname, fname, clearable, allowcommit, 188 statecheckobj = _statecheck(opname, fname, clearable, allowcommit,
186 reportonly, continueflag, stopflag, cmdmsg, 189 reportonly, continueflag, stopflag, cmdmsg,
187 cmdhint, statushint) 190 cmdhint, statushint, abortfunc)
188 if opname == 'merge': 191 if opname == 'merge':
189 _unfinishedstates.append(statecheckobj) 192 _unfinishedstates.append(statecheckobj)
190 else: 193 else:
191 _unfinishedstates.insert(0, statecheckobj) 194 _unfinishedstates.insert(0, statecheckobj)
192 195