diff -r 83aa851f0d84 -r a71e2086fe6e hgkw/keyword.py --- a/hgkw/keyword.py Wed Jan 23 12:33:24 2008 +0100 +++ b/hgkw/keyword.py Fri Jan 25 21:42:52 2008 +0000 @@ -192,10 +192,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 @@ -524,11 +532,14 @@ 'rollback', 'tip', 'convert') try: - hgcmd, func, args, opts, cmdopts = _parse(ui, sys.argv[1:]) - except cmdutil.UnknownCommand: + hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) + 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