changeset 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
files hgext/histedit.py
diffstat 1 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Wed Dec 02 12:19:01 2015 -0800
+++ b/hgext/histedit.py	Wed Dec 02 12:19:01 2015 -0800
@@ -544,6 +544,20 @@
             '--continue, or abort with histedit --abort'))
 
 
+actiontable = {}
+actionlist = []
+
+def addhisteditaction(verbs):
+    def wrap(cls):
+        cls.verb = verbs[0]
+        for verb in verbs:
+            actiontable[verb] = cls
+        actionlist.append(cls)
+        return cls
+    return wrap
+
+
+@addhisteditaction(['pick', 'p'])
 class pick(histeditaction):
     def run(self):
         rulectx = self.repo[self.node]
@@ -553,6 +567,7 @@
 
         return super(pick, self).run()
 
+@addhisteditaction(['edit', 'e'])
 class edit(histeditaction):
     def run(self):
         repo = self.repo
@@ -567,6 +582,7 @@
     def commiteditor(self):
         return cmdutil.getcommiteditor(edit=True, editform='histedit.edit')
 
+@addhisteditaction(['fold', 'f'])
 class fold(histeditaction):
     def continuedirty(self):
         repo = self.repo
@@ -677,6 +693,7 @@
         basectx = self.repo['.']
         return basectx, []
 
+@addhisteditaction(['_multifold'])
 class _multifold(fold):
     """fold subclass used for when multiple folds happen in a row
 
@@ -689,6 +706,7 @@
     def skipprompt(self):
         return True
 
+@addhisteditaction(["roll", "r"])
 class rollup(fold):
     def mergedescs(self):
         return False
@@ -696,11 +714,13 @@
     def skipprompt(self):
         return True
 
+@addhisteditaction(["drop", "d"])
 class drop(histeditaction):
     def run(self):
         parentctx = self.repo[self.state.parentctxnode]
         return parentctx, [(self.node, tuple())]
 
+@addhisteditaction(["mess", "m"])
 class message(histeditaction):
     def commiteditor(self):
         return cmdutil.getcommiteditor(edit=True, editform='histedit.mess')
@@ -731,20 +751,6 @@
         raise error.Abort(msg, hint=hint)
     return repo.lookup(roots[0])
 
-actiontable = {'p': pick,
-               'pick': pick,
-               'e': edit,
-               'edit': edit,
-               'f': fold,
-               'fold': fold,
-               '_multifold': _multifold,
-               'r': rollup,
-               'roll': rollup,
-               'd': drop,
-               'drop': drop,
-               'm': message,
-               'mess': message,
-               }
 
 @command('histedit',
     [('', 'commands', '',
@@ -1379,4 +1385,4 @@
         ['histedit-state', False, True, _('histedit in progress'),
          _("use 'hg histedit --continue' or 'hg histedit --abort'")])
     if ui.configbool("experimental", "histeditng"):
-        actiontable.update({'b': base, 'base': base})
+        globals()['base'] = addhisteditaction(['base', 'b'])(base)