Mercurial > hg
changeset 28134:df206e030c59
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.
author | Kostia Balytskyi <ikostia@fb.com> |
---|---|
date | Sun, 14 Feb 2016 21:15:59 +0000 |
parents | 8fc55388ece5 |
children | ecfa82447162 |
files | hgext/histedit.py |
diffstat | 1 files changed, 19 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/histedit.py Sun Feb 14 21:00:05 2016 +0000 +++ b/hgext/histedit.py Sun Feb 14 21:15:59 2016 +0000 @@ -982,7 +982,16 @@ 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 @@ # 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,8 +1036,13 @@ 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) - state.keep = opts.get('keep', False) + _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs) # rebuild state if goal == 'continue':