Mercurial > hg
comparison hgext/histedit.py @ 27201:dcb536d2e138
histedit: add addhisteditaction decorator
This decorator will is allowing us to move the registering the action
in actiontable closer to the action code. Also it is storing the
verb inside histedit action so the action is aware of the verb
needed to trigger it.
author | Mateusz Kwapich <mitrandir@fb.com> |
---|---|
date | Wed, 02 Dec 2015 12:19:01 -0800 |
parents | 62b9a87a365e |
children | 2226cd4f32ed |
comparison
equal
deleted
inserted
replaced
27200:62b9a87a365e | 27201:dcb536d2e138 |
---|---|
542 raise error.Abort(_('working copy has pending changes'), | 542 raise error.Abort(_('working copy has pending changes'), |
543 hint=_('amend, commit, or revert them and run histedit ' | 543 hint=_('amend, commit, or revert them and run histedit ' |
544 '--continue, or abort with histedit --abort')) | 544 '--continue, or abort with histedit --abort')) |
545 | 545 |
546 | 546 |
547 actiontable = {} | |
548 actionlist = [] | |
549 | |
550 def addhisteditaction(verbs): | |
551 def wrap(cls): | |
552 cls.verb = verbs[0] | |
553 for verb in verbs: | |
554 actiontable[verb] = cls | |
555 actionlist.append(cls) | |
556 return cls | |
557 return wrap | |
558 | |
559 | |
560 @addhisteditaction(['pick', 'p']) | |
547 class pick(histeditaction): | 561 class pick(histeditaction): |
548 def run(self): | 562 def run(self): |
549 rulectx = self.repo[self.node] | 563 rulectx = self.repo[self.node] |
550 if rulectx.parents()[0].node() == self.state.parentctxnode: | 564 if rulectx.parents()[0].node() == self.state.parentctxnode: |
551 self.repo.ui.debug('node %s unchanged\n' % node.short(self.node)) | 565 self.repo.ui.debug('node %s unchanged\n' % node.short(self.node)) |
552 return rulectx, [] | 566 return rulectx, [] |
553 | 567 |
554 return super(pick, self).run() | 568 return super(pick, self).run() |
555 | 569 |
570 @addhisteditaction(['edit', 'e']) | |
556 class edit(histeditaction): | 571 class edit(histeditaction): |
557 def run(self): | 572 def run(self): |
558 repo = self.repo | 573 repo = self.repo |
559 rulectx = repo[self.node] | 574 rulectx = repo[self.node] |
560 hg.update(repo, self.state.parentctxnode) | 575 hg.update(repo, self.state.parentctxnode) |
565 'resume.')) | 580 'resume.')) |
566 | 581 |
567 def commiteditor(self): | 582 def commiteditor(self): |
568 return cmdutil.getcommiteditor(edit=True, editform='histedit.edit') | 583 return cmdutil.getcommiteditor(edit=True, editform='histedit.edit') |
569 | 584 |
585 @addhisteditaction(['fold', 'f']) | |
570 class fold(histeditaction): | 586 class fold(histeditaction): |
571 def continuedirty(self): | 587 def continuedirty(self): |
572 repo = self.repo | 588 repo = self.repo |
573 rulectx = repo[self.node] | 589 rulectx = repo[self.node] |
574 | 590 |
675 | 691 |
676 def continueclean(self): | 692 def continueclean(self): |
677 basectx = self.repo['.'] | 693 basectx = self.repo['.'] |
678 return basectx, [] | 694 return basectx, [] |
679 | 695 |
696 @addhisteditaction(['_multifold']) | |
680 class _multifold(fold): | 697 class _multifold(fold): |
681 """fold subclass used for when multiple folds happen in a row | 698 """fold subclass used for when multiple folds happen in a row |
682 | 699 |
683 We only want to fire the editor for the folded message once when | 700 We only want to fire the editor for the folded message once when |
684 (say) four changes are folded down into a single change. This is | 701 (say) four changes are folded down into a single change. This is |
687 commit messages in their editor. | 704 commit messages in their editor. |
688 """ | 705 """ |
689 def skipprompt(self): | 706 def skipprompt(self): |
690 return True | 707 return True |
691 | 708 |
709 @addhisteditaction(["roll", "r"]) | |
692 class rollup(fold): | 710 class rollup(fold): |
693 def mergedescs(self): | 711 def mergedescs(self): |
694 return False | 712 return False |
695 | 713 |
696 def skipprompt(self): | 714 def skipprompt(self): |
697 return True | 715 return True |
698 | 716 |
717 @addhisteditaction(["drop", "d"]) | |
699 class drop(histeditaction): | 718 class drop(histeditaction): |
700 def run(self): | 719 def run(self): |
701 parentctx = self.repo[self.state.parentctxnode] | 720 parentctx = self.repo[self.state.parentctxnode] |
702 return parentctx, [(self.node, tuple())] | 721 return parentctx, [(self.node, tuple())] |
703 | 722 |
723 @addhisteditaction(["mess", "m"]) | |
704 class message(histeditaction): | 724 class message(histeditaction): |
705 def commiteditor(self): | 725 def commiteditor(self): |
706 return cmdutil.getcommiteditor(edit=True, editform='histedit.mess') | 726 return cmdutil.getcommiteditor(edit=True, editform='histedit.mess') |
707 | 727 |
708 def findoutgoing(ui, repo, remote=None, force=False, opts=None): | 728 def findoutgoing(ui, repo, remote=None, force=False, opts=None): |
729 msg = _('there are ambiguous outgoing revisions') | 749 msg = _('there are ambiguous outgoing revisions') |
730 hint = _('see "hg help histedit" for more detail') | 750 hint = _('see "hg help histedit" for more detail') |
731 raise error.Abort(msg, hint=hint) | 751 raise error.Abort(msg, hint=hint) |
732 return repo.lookup(roots[0]) | 752 return repo.lookup(roots[0]) |
733 | 753 |
734 actiontable = {'p': pick, | |
735 'pick': pick, | |
736 'e': edit, | |
737 'edit': edit, | |
738 'f': fold, | |
739 'fold': fold, | |
740 '_multifold': _multifold, | |
741 'r': rollup, | |
742 'roll': rollup, | |
743 'd': drop, | |
744 'drop': drop, | |
745 'm': message, | |
746 'mess': message, | |
747 } | |
748 | 754 |
749 @command('histedit', | 755 @command('histedit', |
750 [('', 'commands', '', | 756 [('', 'commands', '', |
751 _('read history edits from the specified file'), _('FILE')), | 757 _('read history edits from the specified file'), _('FILE')), |
752 ('c', 'continue', False, _('continue an edit already in progress')), | 758 ('c', 'continue', False, _('continue an edit already in progress')), |
1377 cmdutil.summaryhooks.add('histedit', summaryhook) | 1383 cmdutil.summaryhooks.add('histedit', summaryhook) |
1378 cmdutil.unfinishedstates.append( | 1384 cmdutil.unfinishedstates.append( |
1379 ['histedit-state', False, True, _('histedit in progress'), | 1385 ['histedit-state', False, True, _('histedit in progress'), |
1380 _("use 'hg histedit --continue' or 'hg histedit --abort'")]) | 1386 _("use 'hg histedit --continue' or 'hg histedit --abort'")]) |
1381 if ui.configbool("experimental", "histeditng"): | 1387 if ui.configbool("experimental", "histeditng"): |
1382 actiontable.update({'b': base, 'base': base}) | 1388 globals()['base'] = addhisteditaction(['base', 'b'])(base) |