hgkw/keyword.py
branch0.9.2compat
changeset 352 a71e2086fe6e
parent 350 83aa851f0d84
child 359 4ac7e51443fe
equal deleted inserted replaced
350:83aa851f0d84 352:a71e2086fe6e
   190 commands.optionalrepo += ' kwdemo'
   190 commands.optionalrepo += ' kwdemo'
   191 
   191 
   192 # handle for external callers
   192 # handle for external callers
   193 externalcall = None, None, {}
   193 externalcall = None, None, {}
   194 
   194 
   195 # hook for external callers
       
   196 def externalcmdhook(hgcmd, *args, **opts):
   195 def externalcmdhook(hgcmd, *args, **opts):
       
   196     '''Hook for external callers to pass hg commands to keyword.
       
   197 
       
   198     Caveat: hgcmd, args, opts are not checked for validity.
       
   199     This is the responsibility of the caller.
       
   200 
       
   201     hgmcd can be either the hg function object, eg diff or patch,
       
   202     or its string represenation, eg 'diff' or 'patch'.'''
   197     global externalcall
   203     global externalcall
   198     externalcall = hgcmd.__name__, args, opts
   204     if not isinstance(hgcmd, str):
       
   205         hgcmd = hgcmd.__name__.split('.')[-1]
       
   206     externalcall = hgcmd, args, opts
   199 
   207 
   200 # hg commands that trigger expansion only when writing to working dir,
   208 # hg commands that trigger expansion only when writing to working dir,
   201 # not when reading filelog, and unexpand when reading from working dir
   209 # not when reading filelog, and unexpand when reading from working dir
   202 restricted = ('diff1', 'record',
   210 restricted = ('diff1', 'record',
   203               'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
   211               'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
   522                     'export', 'grep', 'identify', 'incoming', 'init',
   530                     'export', 'grep', 'identify', 'incoming', 'init',
   523                     'log', 'outgoing', 'push', 'remove', 'rename',
   531                     'log', 'outgoing', 'push', 'remove', 'rename',
   524                     'rollback', 'tip',
   532                     'rollback', 'tip',
   525                     'convert')
   533                     'convert')
   526     try:
   534     try:
   527         hgcmd, func, args, opts, cmdopts = _parse(ui, sys.argv[1:])
   535         hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
   528     except cmdutil.UnknownCommand:
   536     except (cmdutil.UnknownCommand, dispatch.ParseError):
       
   537         # must be an external caller, otherwise Exception would have been
       
   538         # raised at core command line parsing
   529         hgcmd, args, cmdopts = externalcall
   539         hgcmd, args, cmdopts = externalcall
   530         if hgcmd is None:  # no command was specified from outside
   540         if hgcmd is None:
   531             raise
   541             # not an "official" hg command as from command line
       
   542             return
   532     if hgcmd in nokwcommands:
   543     if hgcmd in nokwcommands:
   533         return
   544         return
   534 
   545 
   535     if hgcmd == 'diff':
   546     if hgcmd == 'diff':
   536         # only expand if comparing against working dir
   547         # only expand if comparing against working dir