hgkw/keyword.py
changeset 351 19d5f328a979
parent 349 c78c74451bac
child 353 159bf80a4301
equal deleted inserted replaced
349:c78c74451bac 351:19d5f328a979
    89 commands.optionalrepo += ' kwdemo'
    89 commands.optionalrepo += ' kwdemo'
    90 
    90 
    91 # handle for external callers
    91 # handle for external callers
    92 externalcall = None, None, {}
    92 externalcall = None, None, {}
    93 
    93 
    94 # hook for external callers
       
    95 def externalcmdhook(hgcmd, *args, **opts):
    94 def externalcmdhook(hgcmd, *args, **opts):
       
    95     '''Hook for external callers to pass hg commands to keyword.
       
    96 
       
    97     Caveat: hgcmd, args, opts are not checked for validity.
       
    98     This is the responsibility of the caller.
       
    99 
       
   100     hgmcd can be either the hg function object, eg diff or patch,
       
   101     or its string represenation, eg 'diff' or 'patch'.'''
    96     global externalcall
   102     global externalcall
    97     externalcall = hgcmd.__name__, args, opts
   103     if not isinstance(hgcmd, str):
       
   104         hgcmd = hgcmd.__name__.split('.')[-1]
       
   105     externalcall = hgcmd, args, opts
    98 
   106 
    99 # hg commands that trigger expansion only when writing to working dir,
   107 # hg commands that trigger expansion only when writing to working dir,
   100 # not when reading filelog, and unexpand when reading from working dir
   108 # not when reading filelog, and unexpand when reading from working dir
   101 restricted = ('diff1', 'record',
   109 restricted = ('diff1', 'record',
   102               'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
   110               'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
   424                     'log', 'outgoing', 'push', 'remove', 'rename',
   432                     'log', 'outgoing', 'push', 'remove', 'rename',
   425                     'rollback', 'tip',
   433                     'rollback', 'tip',
   426                     'convert')
   434                     'convert')
   427     try:
   435     try:
   428         hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
   436         hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
   429     except cmdutil.UnknownCommand:
   437     except (cmdutil.UnknownCommand, dispatch.ParseError):
       
   438         # must be an external caller, otherwise Exception would have been
       
   439         # raised at core command line parsing
   430         hgcmd, args, cmdopts = externalcall
   440         hgcmd, args, cmdopts = externalcall
   431         if hgcmd is None:  # no command was specified from outside
   441         if hgcmd is None:
   432             raise
   442             # not an "official" hg command as from command line
       
   443             return
   433     if hgcmd in nokwcommands:
   444     if hgcmd in nokwcommands:
   434         return
   445         return
   435 
   446 
   436     if hgcmd == 'diff':
   447     if hgcmd == 'diff':
   437         # only expand if comparing against working dir
   448         # only expand if comparing against working dir