# HG changeset patch # User Christian Ebert # Date 1201282315 0 # Node ID 19d5f328a979485e7c00369699b8c9739090446c # Parent c78c74451bac7ee17a1135c6ad1a9e630693ac0a Return silently when external command triggers error - make hook accept hg command as string or as function object. - intercept dispatch.ParseError as well. Kudos to Steve Borho (TortoiseHg) for testing and debugging. diff -r c78c74451bac -r 19d5f328a979 hgkw/keyword.py --- 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