Mercurial > hg
comparison hgext/histedit.py @ 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 | ed6d650b7cb7 |
comparison
equal
deleted
inserted
replaced
28133:8fc55388ece5 | 28134:df206e030c59 |
---|---|
980 state.lock = repo.lock() | 980 state.lock = repo.lock() |
981 _histedit(ui, repo, state, *freeargs, **opts) | 981 _histedit(ui, repo, state, *freeargs, **opts) |
982 finally: | 982 finally: |
983 release(state.lock, state.wlock) | 983 release(state.lock, state.wlock) |
984 | 984 |
985 def _histedit(ui, repo, state, *freeargs, **opts): | 985 def _getgoal(opts): |
986 if opts.get('continue'): | |
987 return 'continue' | |
988 if opts.get('abort'): | |
989 return 'abort' | |
990 if opts.get('edit_plan'): | |
991 return 'edit-plan' | |
992 return 'new' | |
993 | |
994 def _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs): | |
986 # TODO only abort if we try to histedit mq patches, not just | 995 # TODO only abort if we try to histedit mq patches, not just |
987 # blanket if mq patches are applied somewhere | 996 # blanket if mq patches are applied somewhere |
988 mq = getattr(repo, 'mq', None) | 997 mq = getattr(repo, 'mq', None) |
989 if mq and mq.applied: | 998 if mq and mq.applied: |
990 raise error.Abort(_('source has mq patches applied')) | 999 raise error.Abort(_('source has mq patches applied')) |
991 | 1000 |
992 # basic argument incompatibility processing | 1001 # basic argument incompatibility processing |
993 outg = opts.get('outgoing') | 1002 outg = opts.get('outgoing') |
994 cont = opts.get('continue') | |
995 editplan = opts.get('edit_plan') | 1003 editplan = opts.get('edit_plan') |
996 abort = opts.get('abort') | 1004 abort = opts.get('abort') |
997 force = opts.get('force') | 1005 force = opts.get('force') |
998 rules = opts.get('commands', '') | |
999 revs = opts.get('rev', []) | |
1000 goal = 'new' # This invocation goal, in new, continue, abort | |
1001 if force and not outg: | 1006 if force and not outg: |
1002 raise error.Abort(_('--force only allowed with --outgoing')) | 1007 raise error.Abort(_('--force only allowed with --outgoing')) |
1003 if cont: | 1008 if goal == 'continue': |
1004 if any((outg, abort, revs, freeargs, rules, editplan)): | 1009 if any((outg, abort, revs, freeargs, rules, editplan)): |
1005 raise error.Abort(_('no arguments allowed with --continue')) | 1010 raise error.Abort(_('no arguments allowed with --continue')) |
1006 goal = 'continue' | 1011 elif goal == 'abort': |
1007 elif abort: | |
1008 if any((outg, revs, freeargs, rules, editplan)): | 1012 if any((outg, revs, freeargs, rules, editplan)): |
1009 raise error.Abort(_('no arguments allowed with --abort')) | 1013 raise error.Abort(_('no arguments allowed with --abort')) |
1010 goal = 'abort' | 1014 elif goal == 'edit-plan': |
1011 elif editplan: | |
1012 if any((outg, revs, freeargs)): | 1015 if any((outg, revs, freeargs)): |
1013 raise error.Abort(_('only --commands argument allowed with ' | 1016 raise error.Abort(_('only --commands argument allowed with ' |
1014 '--edit-plan')) | 1017 '--edit-plan')) |
1015 goal = 'edit-plan' | |
1016 else: | 1018 else: |
1017 if os.path.exists(os.path.join(repo.path, 'histedit-state')): | 1019 if os.path.exists(os.path.join(repo.path, 'histedit-state')): |
1018 raise error.Abort(_('history edit already in progress, try ' | 1020 raise error.Abort(_('history edit already in progress, try ' |
1019 '--continue or --abort')) | 1021 '--continue or --abort')) |
1020 if outg: | 1022 if outg: |
1032 | 1034 |
1033 if len(revs) != 1: | 1035 if len(revs) != 1: |
1034 raise error.Abort( | 1036 raise error.Abort( |
1035 _('histedit requires exactly one ancestor revision')) | 1037 _('histedit requires exactly one ancestor revision')) |
1036 | 1038 |
1037 | 1039 def _histedit(ui, repo, state, *freeargs, **opts): |
1040 goal = _getgoal(opts) | |
1041 revs = opts.get('rev', []) | |
1042 rules = opts.get('commands', '') | |
1038 state.keep = opts.get('keep', False) | 1043 state.keep = opts.get('keep', False) |
1044 | |
1045 _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs) | |
1039 | 1046 |
1040 # rebuild state | 1047 # rebuild state |
1041 if goal == 'continue': | 1048 if goal == 'continue': |
1042 state.read() | 1049 state.read() |
1043 state = bootstrapcontinue(ui, state, opts) | 1050 state = bootstrapcontinue(ui, state, opts) |