hgkw/keyword.py
changeset 228 88362a9b5afd
parent 227 8ae160f24b9f
child 229 8e5ba738e36d
equal deleted inserted replaced
227:8ae160f24b9f 228:88362a9b5afd
    85 from mercurial.i18n import gettext as _
    85 from mercurial.i18n import gettext as _
    86 import getopt, re, shutil, sys, tempfile, time
    86 import getopt, re, shutil, sys, tempfile, time
    87 
    87 
    88 # backwards compatibility hacks
    88 # backwards compatibility hacks
    89 
    89 
    90 # findcmd, bail_if_changed were in commands until 0c61124ad877
       
    91 try:
    90 try:
    92     findcmd = cmdutil.findcmd
    91     # cmdutil.parse moves to dispatch._parse in 18a9fbb5cd78
    93     bail_if_changed = cmdutil.bail_if_changed
    92     from mercurial import dispatch
       
    93     __parse = dispatch._parse
       
    94 except ImportError:
       
    95     try:
       
    96         # commands.parse moves to cmdutil.parse in 0c61124ad877
       
    97         __parse = cmdutil.parse
       
    98     except AttributeError:
       
    99         __parse = commands.parse
       
   100 
       
   101 try:
       
   102     # bail_if_changed moves from commands to cmdutil in 0c61124ad877
       
   103     _bail_if_changed = cmdutil.bail_if_changed
    94 except AttributeError:
   104 except AttributeError:
    95     findcmd = commands.findcmd
   105     _bail_if_changed = commands.bail_if_changed
    96     bail_if_changed = commands.bail_if_changed
       
    97 
       
    98 # cmdutil.parse moves to dispatch._parse in 18a9fbb5cd78
       
    99 try:
       
   100     from mercurial import dispatch
       
   101 except ImportError:
       
   102     pass
       
   103 
   106 
   104 # commands.parse/cmdutil.parse returned nothing for
   107 # commands.parse/cmdutil.parse returned nothing for
   105 # "hg diff --rev" before 88803a69b24a due to bug in fancyopts
   108 # "hg diff --rev" before 88803a69b24a due to bug in fancyopts
   106 def _fancyopts(args, options, state):
   109 def _fancyopts(args, options, state):
   107     '''Fixed fancyopts from 88803a69b24a.'''
   110     '''Fixed fancyopts from 88803a69b24a.'''
   310     '''Expands/shrinks keywords in working directory.'''
   313     '''Expands/shrinks keywords in working directory.'''
   311     wlock = lock = None
   314     wlock = lock = None
   312     try:
   315     try:
   313         wlock = repo.wlock()
   316         wlock = repo.wlock()
   314         lock = repo.lock()
   317         lock = repo.lock()
   315         bail_if_changed(repo)
   318         _bail_if_changed(repo)
   316         ctx = repo.changectx()
   319         ctx = repo.changectx()
   317         if not ctx:
   320         if not ctx:
   318             raise hg.RepoError(_('no revision checked out'))
   321             raise hg.RepoError(_('no revision checked out'))
   319         kwfmatcher = _keywordmatcher(ui, repo)
   322         kwfmatcher = _keywordmatcher(ui, repo)
   320         if kwfmatcher is None:
   323         if kwfmatcher is None:
   437 
   440 
   438     nokwcommands = ['add', 'addremove', 'bundle', 'clone', 'copy', 'export',
   441     nokwcommands = ['add', 'addremove', 'bundle', 'clone', 'copy', 'export',
   439                     'grep', 'identify', 'incoming', 'init', 'outgoing', 'push',
   442                     'grep', 'identify', 'incoming', 'init', 'outgoing', 'push',
   440                     'remove', 'rename', 'rollback']
   443                     'remove', 'rename', 'rollback']
   441 
   444 
   442     def _getcmd():
   445     if not repo.local() or __parse(ui, sys.argv[1:])[0] in nokwcommands:
   443         try:
       
   444             return dispatch._parse(ui, sys.argv[1:])[0]
       
   445         except (ImportError, NameError):
       
   446             try:
       
   447                 return cmdutil.parse(ui, sys.argv[1:])[0]
       
   448             except AttributeError:
       
   449                 return commands.parse(ui, sys.argv[1:])[0]
       
   450 
       
   451     if not repo.local() or _getcmd() in nokwcommands:
       
   452         return
   446         return
   453 
   447 
   454     kwfmatcher = _keywordmatcher(ui, repo)
   448     kwfmatcher = _keywordmatcher(ui, repo)
   455     if kwfmatcher is None:
   449     if kwfmatcher is None:
   456         return
   450         return