# HG changeset patch # User Kostia Balytskyi # Date 2016-02-14 21:15:59 # Node ID df206e030c59c844cd060c77746dcad4f7498b8e # Parent 8fc55388ece5148c746f77c401d0a438849ae379 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. diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -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 # 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 @@ def _histedit(ui, repo, state, *freeargs 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':