[PATCH 1 of 5 evolve-ext] wrapcommand: allow adding additional arguments to commands

Durham Goode durham at fb.com
Thu Mar 19 20:14:26 CDT 2015

# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1426787548 25200
#      Thu Mar 19 10:52:28 2015 -0700
# Node ID 7b7ed492d4d6437cfcfdc357842e91c3910ae834
# Parent  4b10e2c6f7e35590eb17525c53f2c0cfe2e9cd4b
wrapcommand: allow adding additional arguments to commands

This allows eh.wrapcommand to specify additional parameters to be added to the
commands being wrapped.  This will be useful when wrapping strip in the future.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -141,8 +141,11 @@ class exthelper(object):
         for cont, funcname, func in self._duckpunchers:
             setattr(cont, funcname, func)
-        for command, wrapper in self._commandwrappers:
-            extensions.wrapcommand(commands.table, command, wrapper)
+        for command, wrapper, opts in self._commandwrappers:
+            entry = extensions.wrapcommand(commands.table, command, wrapper)
+            if opts:
+                for short, long, val, msg in opts:
+                    entry[1].append((short, long, val, msg))
         for cont, funcname, wrapper in self._functionwrappers:
             extensions.wrapfunction(cont, funcname, wrapper)
         for c in self._uicallables:
@@ -163,13 +166,17 @@ class exthelper(object):
             revset.symbols[name] = symbol
         for name, kw in self._templatekws:
             templatekw.keywords[name] = kw
-        for ext, command, wrapper in self._extcommandwrappers:
+        for ext, command, wrapper, opts in self._extcommandwrappers:
             if ext not in knownexts:
                 e = extensions.find(ext)
                 if e is None:
                     raise util.Abort('extension %s not found' % ext)
                 knownexts[ext] = e.cmdtable
-            extensions.wrapcommand(knownexts[ext], commands, wrapper)
+            entry = extensions.wrapcommand(knownexts[ext], command, wrapper)
+            if opts:
+                for short, long, val, msg in opts:
+                    entry[1].append((short, long, val, msg))
         for c in self._extcallables:
@@ -257,7 +264,7 @@ class exthelper(object):
             return keyword
         return dec
-    def wrapcommand(self, command, extension=None):
+    def wrapcommand(self, command, extension=None, opts=[]):
         """Decorated function is a command wrapper
         The name of the command must be given as the decorator argument.
@@ -276,12 +283,16 @@ class exthelper(object):
                 return orig(ui, repo, *args, **kwargs)
+        The `opts` argument allows specifying additional arguments for the
+        command.
         def dec(wrapper):
             if extension is None:
-                self._commandwrappers.append((command, wrapper))
+                self._commandwrappers.append((command, wrapper, opts))
-                self._extcommandwrappers.append((extension, command, wrapper))
+                self._extcommandwrappers.append((extension, command, wrapper,
+                    opts))
             return wrapper
         return dec

More information about the Mercurial-devel mailing list