histedit: break _histedit function into smaller pieces

We add _getgoal, _validateargs.

This is a part of bigger effort to refactor histedit. Initial steps are to
break _histedit function into smaller pieces which will supposedly be more
understandable. After this is done, I will have a better understanding
of how histedit works and apply that to fix issue4800.
This commit is contained in:
Kostia Balytskyi 2016-02-14 21:15:59 +00:00
parent c6f4a6c3fa
commit 41ac3675d5

View File

@ -982,7 +982,16 @@ def histedit(ui, repo, *freeargs, **opts):
finally:
release(state.lock, state.wlock)
def _histedit(ui, repo, state, *freeargs, **opts):
def _getgoal(opts):
if opts.get('continue'):
return 'continue'
if opts.get('abort'):
return 'abort'
if opts.get('edit_plan'):
return 'edit-plan'
return 'new'
def _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs):
# TODO only abort if we try to histedit mq patches, not just
# blanket if mq patches are applied somewhere
mq = getattr(repo, 'mq', None)
@ -991,28 +1000,21 @@ def _histedit(ui, repo, state, *freeargs, **opts):
# basic argument incompatibility processing
outg = opts.get('outgoing')
cont = opts.get('continue')
editplan = opts.get('edit_plan')
abort = opts.get('abort')
force = opts.get('force')
rules = opts.get('commands', '')
revs = opts.get('rev', [])
goal = 'new' # This invocation goal, in new, continue, abort
if force and not outg:
raise error.Abort(_('--force only allowed with --outgoing'))
if cont:
if goal == 'continue':
if any((outg, abort, revs, freeargs, rules, editplan)):
raise error.Abort(_('no arguments allowed with --continue'))
goal = 'continue'
elif abort:
elif goal == 'abort':
if any((outg, revs, freeargs, rules, editplan)):
raise error.Abort(_('no arguments allowed with --abort'))
goal = 'abort'
elif editplan:
elif goal == 'edit-plan':
if any((outg, revs, freeargs)):
raise error.Abort(_('only --commands argument allowed with '
'--edit-plan'))
goal = 'edit-plan'
else:
if os.path.exists(os.path.join(repo.path, 'histedit-state')):
raise error.Abort(_('history edit already in progress, try '
@ -1034,9 +1036,14 @@ def _histedit(ui, repo, state, *freeargs, **opts):
raise error.Abort(
_('histedit requires exactly one ancestor revision'))
def _histedit(ui, repo, state, *freeargs, **opts):
goal = _getgoal(opts)
revs = opts.get('rev', [])
rules = opts.get('commands', '')
state.keep = opts.get('keep', False)
_validateargs(ui, repo, state, freeargs, opts, goal, rules, revs)
# rebuild state
if goal == 'continue':
state.read()