Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.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 |
---|---|
3312 # otherwise, 'changes' is a tuple of tuples below: | 3312 # otherwise, 'changes' is a tuple of tuples below: |
3313 # - (sourceurl, sourcebranch, sourcepeer, incoming) | 3313 # - (sourceurl, sourcebranch, sourcepeer, incoming) |
3314 # - (desturl, destbranch, destpeer, outgoing) | 3314 # - (desturl, destbranch, destpeer, outgoing) |
3315 summaryremotehooks = util.hooks() | 3315 summaryremotehooks = util.hooks() |
3316 | 3316 |
3317 | |
3317 def checkunfinished(repo, commit=False): | 3318 def checkunfinished(repo, commit=False): |
3318 '''Look for an unfinished multistep operation, like graft, and abort | 3319 '''Look for an unfinished multistep operation, like graft, and abort |
3319 if found. It's probably good to check this right before | 3320 if found. It's probably good to check this right before |
3320 bailifchanged(). | 3321 bailifchanged(). |
3321 ''' | 3322 ''' |
3322 # Check for non-clearable states first, so things like rebase will take | 3323 # Check for non-clearable states first, so things like rebase will take |
3323 # precedence over update. | 3324 # precedence over update. |
3324 for f, clearable, allowcommit, msg, hint in statemod.unfinishedstates: | 3325 for state in statemod._unfinishedstates: |
3325 if clearable or (commit and allowcommit): | 3326 if state._clearable or (commit and state._allowcommit): |
3326 continue | 3327 continue |
3327 if repo.vfs.exists(f): | 3328 if state.isunfinished(repo): |
3328 raise error.Abort(msg, hint=hint) | 3329 raise error.Abort(state.msg(), hint=state.hint()) |
3329 | 3330 |
3330 for f, clearable, allowcommit, msg, hint in statemod.unfinishedstates: | 3331 for s in statemod._unfinishedstates: |
3331 if not clearable or (commit and allowcommit): | 3332 if not s._clearable or (commit and s._allowcommit): |
3332 continue | 3333 continue |
3333 if repo.vfs.exists(f): | 3334 if s.isunfinished(repo): |
3334 raise error.Abort(msg, hint=hint) | 3335 raise error.Abort(s.msg(), hint=s.hint()) |
3335 | 3336 |
3336 def clearunfinished(repo): | 3337 def clearunfinished(repo): |
3337 '''Check for unfinished operations (as above), and clear the ones | 3338 '''Check for unfinished operations (as above), and clear the ones |
3338 that are clearable. | 3339 that are clearable. |
3339 ''' | 3340 ''' |
3340 for f, clearable, allowcommit, msg, hint in statemod.unfinishedstates: | 3341 for state in statemod._unfinishedstates: |
3341 if not clearable and repo.vfs.exists(f): | 3342 if not state._clearable and state.isunfinished(repo): |
3342 raise error.Abort(msg, hint=hint) | 3343 raise error.Abort(state.msg(), hint=state.hint()) |
3343 for f, clearable, allowcommit, msg, hint in statemod.unfinishedstates: | 3344 |
3344 if clearable and repo.vfs.exists(f): | 3345 for s in statemod._unfinishedstates: |
3345 util.unlink(repo.vfs.join(f)) | 3346 if s._clearable and s.isunfinished(repo): |
3347 util.unlink(repo.vfs.join(s._fname)) | |
3346 | 3348 |
3347 afterresolvedstates = [ | 3349 afterresolvedstates = [ |
3348 ('graftstate', | 3350 ('graftstate', |
3349 _('hg graft --continue')), | 3351 _('hg graft --continue')), |
3350 ] | 3352 ] |