[PATCH 2 of 9] histedit: add addhisteditaction decorator

Mateusz Kwapich mitrandir at fb.com
Wed Dec 2 14:22:54 CST 2015


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1449087541 28800
#      Wed Dec 02 12:19:01 2015 -0800
# Node ID bd6573e0e6afe2416572343d38547917e3205ac0
# Parent  3a18e4a826d770a29724ac8de8f04f3f89465628
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.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -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
+
+
+ at addhisteditaction(['pick', 'p'])
 class pick(histeditaction):
     def run(self):
         rulectx = self.repo[self.node]
@@ -553,6 +567,7 @@
 
         return super(pick, self).run()
 
+ at 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')
 
+ at addhisteditaction(['fold', 'f'])
 class fold(histeditaction):
     def continuedirty(self):
         repo = self.repo
@@ -677,6 +693,7 @@
         basectx = self.repo['.']
         return basectx, []
 
+ at 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
 
+ at addhisteditaction(["roll", "r"])
 class rollup(fold):
     def mergedescs(self):
         return False
@@ -696,11 +714,13 @@
     def skipprompt(self):
         return True
 
+ at addhisteditaction(["drop", "d"])
 class drop(histeditaction):
     def run(self):
         parentctx = self.repo[self.state.parentctxnode]
         return parentctx, [(self.node, tuple())]
 
+ at 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)


More information about the Mercurial-devel mailing list