# HG changeset patch # User Christian Ebert # Date 1201087901 -3600 # Node ID c78c74451bac7ee17a1135c6ad1a9e630693ac0a # Parent c912b8c3f3ff20a161feeadd351fe5c88259e8bf Implement handle and hook for external callers Allows external callers that do not use the command line to pass current hg command to keyword extension. This implementation might change in the future, if wrapping of patch.diff is possible to the effect of avoiding external handles. diff -r c912b8c3f3ff -r c78c74451bac hgkw/keyword.py --- a/hgkw/keyword.py Wed Jan 23 11:36:37 2008 +0100 +++ b/hgkw/keyword.py Wed Jan 23 12:31:41 2008 +0100 @@ -88,6 +88,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', @@ -416,7 +424,12 @@ 'log', 'outgoing', 'push', 'remove', 'rename', 'rollback', 'tip', 'convert') - hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) + try: + hgcmd, func, args, opts, cmdopts = dispatch._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