(0.9.2compat) implement external call handle and hook 0.9.2compat
authorChristian Ebert <blacktrash@gmx.net>
Wed, 23 Jan 2008 12:33:24 +0100
branch0.9.2compat
changeset 350 83aa851f0d84
parent 348 63ebc698d06b
child 352 a71e2086fe6e
(0.9.2compat) implement external call handle and hook
hgkw/keyword.py
--- a/hgkw/keyword.py	Wed Jan 23 11:38:22 2008 +0100
+++ b/hgkw/keyword.py	Wed Jan 23 12:33:24 2008 +0100
@@ -189,6 +189,14 @@
 
 commands.optionalrepo += ' kwdemo'
 
+# handle for external callers
+externalcall = None, None, {}
+
+# hook for external callers
+def externalcmdhook(hgcmd, *args, **opts):
+    global externalcall
+    externalcall = hgcmd.__name__, args, opts
+
 # hg commands that trigger expansion only when writing to working dir,
 # not when reading filelog, and unexpand when reading from working dir
 restricted = ('diff1', 'record',
@@ -515,7 +523,12 @@
                     'log', 'outgoing', 'push', 'remove', 'rename',
                     'rollback', 'tip',
                     'convert')
-    hgcmd, func, args, opts, cmdopts = _parse(ui, sys.argv[1:])
+    try:
+        hgcmd, func, args, opts, cmdopts = _parse(ui, sys.argv[1:])
+    except cmdutil.UnknownCommand:
+        hgcmd, args, cmdopts = externalcall
+        if hgcmd is None:  # no command was specified from outside
+            raise
     if hgcmd in nokwcommands:
         return