comparison mercurial/state.py @ 42537:dc3fdd1b5af4

state: created new class statecheck to handle unfinishedstates For the purpose of handling states for various multistep operations like `hg graft`, `hg histedit`, `hg bisect` et al a new class called statecheck is created .This will help in having a unified approach towards these commands and handle them with ease. The class takes in 4 basic arguments which include the name of the command, the name of the state file associated with it , clearable flag , allowcommit flag. This also also adds the support of`checkunfinished()` and `clearunfinished()` to the class. Tests remain unchanged. Differential Revision: https://phab.mercurial-scm.org/D6501
author Taapas Agrawal <taapas2897@gmail.com>
date Sun, 09 Jun 2019 00:43:36 +0530
parents 5f2f6912c9e6
children 5bddd2244814
comparison
equal deleted inserted replaced
42536:5f2f6912c9e6 42537:dc3fdd1b5af4
86 86
87 def exists(self): 87 def exists(self):
88 """check whether the state file exists or not""" 88 """check whether the state file exists or not"""
89 return self._repo.vfs.exists(self.fname) 89 return self._repo.vfs.exists(self.fname)
90 90
91 # A list of state files kept by multistep operations like graft. 91 class _statecheck(object):
92 # Since graft cannot be aborted, it is considered 'clearable' by update. 92 """a utility class that deals with multistep operations like graft,
93 # note: bisect is intentionally excluded 93 histedit, bisect, update etc and check whether such commands
94 # (state file, clearable, allowcommit, error, hint) 94 are in an unfinished conditition or not and return appropriate message
95 unfinishedstates = [ 95 and hint.
96 ('graftstate', True, False, _('graft in progress'), 96 It also has the ability to register and determine the states of any new
97 _("use 'hg graft --continue' or 'hg graft --stop' to stop")), 97 multistep operation or multistep command extension.
98 ('updatestate', True, False, _('last update was interrupted'), 98 """
99 _("use 'hg update' to get a consistent checkout")) 99
100 ] 100 def __init__(self, opname, fname, clearable=False, allowcommit=False,
101 cmdmsg="", cmdhint=""):
102 """opname is the name the command or operation
103 fname is the file name in which data should be stored in .hg directory.
104 It is None for merge command.
105 clearable boolean determines whether or not interrupted states can be
106 cleared by running `hg update -C .` which in turn deletes the
107 state file.
108 allowcommit boolean decides whether commit is allowed during interrupted
109 state or not.
110 cmdmsg is used to pass a different status message in case standard
111 message of the format "abort: cmdname in progress" is not desired.
112 cmdhint is used to pass a different hint message in case standard
113 message of the format use 'hg cmdname --continue' or
114 'hg cmdname --abort'" is not desired.
115 """
116 self._opname = opname
117 self._fname = fname
118 self._clearable = clearable
119 self._allowcommit = allowcommit
120 self._cmdhint = cmdhint
121 self._cmdmsg = cmdmsg
122
123 def hint(self):
124 """returns the hint message corresponding to the command"""
125 if not self._cmdhint:
126 return (_("use 'hg %s --continue' or 'hg %s --abort'") %
127 (self._opname, self._opname))
128 return self._cmdhint
129
130 def msg(self):
131 """returns the status message corresponding to the command"""
132 if not self._cmdmsg:
133 return _('%s in progress') % (self._opname)
134 return self._cmdmsg
135
136 def isunfinished(self, repo):
137 """determines whether a multi-step operation is in progress or not"""
138 return repo.vfs.exists(self._fname)
139
140 # A list of statecheck objects for multistep operations like graft.
141 _unfinishedstates = []
142
143 def addunfinished(opname, **kwargs):
144 """this registers a new command or operation to unfinishedstates
145 """
146 statecheckobj = _statecheck(opname, **kwargs)
147 _unfinishedstates.append(statecheckobj)
148
149 addunfinished(
150 'graft', fname='graftstate', clearable=True,
151 cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop")
152 )
153 addunfinished(
154 'update', fname='updatestate', clearable=True,
155 cmdmsg=_('last update was interrupted'),
156 cmdhint=_("use 'hg update' to get a consistent checkout")
157 )