hgkw/keyword.py
changeset 351 19d5f328a979
parent 349 c78c74451bac
child 353 159bf80a4301
--- a/hgkw/keyword.py	Wed Jan 23 12:31:41 2008 +0100
+++ b/hgkw/keyword.py	Fri Jan 25 17:31:55 2008 +0000
@@ -91,10 +91,18 @@
 # handle for external callers
 externalcall = None, None, {}
 
-# hook for external callers
 def externalcmdhook(hgcmd, *args, **opts):
+    '''Hook for external callers to pass hg commands to keyword.
+
+    Caveat: hgcmd, args, opts are not checked for validity.
+    This is the responsibility of the caller.
+
+    hgmcd can be either the hg function object, eg diff or patch,
+    or its string represenation, eg 'diff' or 'patch'.'''
     global externalcall
-    externalcall = hgcmd.__name__, args, opts
+    if not isinstance(hgcmd, str):
+        hgcmd = hgcmd.__name__.split('.')[-1]
+    externalcall = hgcmd, args, opts
 
 # hg commands that trigger expansion only when writing to working dir,
 # not when reading filelog, and unexpand when reading from working dir
@@ -426,10 +434,13 @@
                     'convert')
     try:
         hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
-    except cmdutil.UnknownCommand:
+    except (cmdutil.UnknownCommand, dispatch.ParseError):
+        # must be an external caller, otherwise Exception would have been
+        # raised at core command line parsing
         hgcmd, args, cmdopts = externalcall
-        if hgcmd is None:  # no command was specified from outside
-            raise
+        if hgcmd is None:
+            # not an "official" hg command as from command line
+            return
     if hgcmd in nokwcommands:
         return