hgkw/keyword.py
branch0.9.2compat
changeset 291 acd3fba02a50
parent 288 80a300088654
child 295 5b4039ca6867
equal deleted inserted replaced
289:b8c86166bf86 291:acd3fba02a50
    78 Caveat: "hg import" fails if the patch context contains an active
    78 Caveat: "hg import" fails if the patch context contains an active
    79         keyword. In that case run "hg kwshrink", and then reimport.
    79         keyword. In that case run "hg kwshrink", and then reimport.
    80         Or, better, use bundle/unbundle to share changes.
    80         Or, better, use bundle/unbundle to share changes.
    81 '''
    81 '''
    82 
    82 
    83 from mercurial import commands, cmdutil, context, fancyopts
    83 from mercurial import commands, cmdutil, context
    84 from mercurial import filelog, localrepo, revlog, templater, util
    84 from mercurial import filelog, localrepo, revlog, templater, util
    85 from mercurial.i18n import gettext as _
    85 from mercurial.i18n import gettext as _
    86 import getopt, os.path, re, shutil, sys, tempfile, time
    86 import getopt, os.path, re, shutil, sys, tempfile, time
    87 
    87 
    88 # backwards compatibility hacks
    88 # backwards compatibility hacks
    89 
       
    90 try:
       
    91     # cmdutil.parse moves to dispatch._parse in 18a9fbb5cd78
       
    92     # also avoid name conflict with other dispatch package(s)
       
    93     from mercurial.dispatch import _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 
    89 
   101 def _pathto(repo, f, cwd=None):
    90 def _pathto(repo, f, cwd=None):
   102     '''kwfiles behaves similar to status, using pathto since 78b6add1f966.'''
    91     '''kwfiles behaves similar to status, using pathto since 78b6add1f966.'''
   103     try:
    92     try:
   104         return repo.pathto(f, cwd)
    93         return repo.pathto(f, cwd)
   105     except AttributeError:
    94     except AttributeError:
   106         return f
    95         return f
   107 
    96 
   108 # commands.parse/cmdutil.parse returned nothing for
    97 # commands.parse/cmdutil.parse returned nothing for
   109 # "hg diff --rev" before 88803a69b24a due to bug in fancyopts
    98 # "hg diff --rev" before 88803a69b24a due to bug in fancyopts
   110 def _fancyopts(args, options, state):
    99 def fancyopts(args, options, state):
   111     '''Fixed fancyopts from 88803a69b24a.'''
   100     '''Fixed fancyopts from 88803a69b24a.'''
   112     long = []
   101     long = []
   113     short = ''
   102     short = ''
   114     map = {}
   103     map = {}
   115     dt = {}
   104     dt = {}
   135         elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
   124         elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
   136         elif dt[map[opt]] is type(None): state[map[opt]] = True
   125         elif dt[map[opt]] is type(None): state[map[opt]] = True
   137         elif dt[map[opt]] is type(False): state[map[opt]] = True
   126         elif dt[map[opt]] is type(False): state[map[opt]] = True
   138     return args
   127     return args
   139 
   128 
   140 fancyopts.fancyopts = _fancyopts
   129 def findcmd(ui, cmd, table):
       
   130     '''findcmd has table argument since 18a9fbb5cd78.'''
       
   131     try:
       
   132         return findcmd.findcmd(ui, cmd, table)
       
   133     except TypeError:
       
   134         return findcmd.findcmd(ui, cmd)
       
   135 # findcmd in commands until 0c61124ad877
       
   136 try:
       
   137     findcmd.findcmd = cmdutil.findcmd
       
   138     findcmd.__doc__ = cmdutil.findcmd.__doc__
       
   139 except AttributeError:
       
   140     findcmd.findcmd = commands.findcmd
       
   141     findcmd.__doc__ = commands.findcmd.__doc__
   141 
   142 
   142 
   143 
   143 commands.optionalrepo += ' kwdemo'
   144 commands.optionalrepo += ' kwdemo'
   144 
   145 
   145 def utcdate(date):
   146 def utcdate(date):
   475     Wraps commit to overwrite configured files with updated
   476     Wraps commit to overwrite configured files with updated
   476     keyword substitutions.
   477     keyword substitutions.
   477     This is done for local repos only, and only if there are
   478     This is done for local repos only, and only if there are
   478     files configured at all for keyword substitution.'''
   479     files configured at all for keyword substitution.'''
   479 
   480 
   480     nokwcommands = ['add', 'addremove', 'bundle', 'clone', 'copy', 'export',
   481     nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy', 'export',
   481                     'grep', 'identify', 'incoming', 'init', 'outgoing', 'push',
   482                     'grep', 'identify', 'incoming', 'init', 'outgoing', 'push',
   482                     'remove', 'rename', 'rollback', 'convert']
   483                     'remove', 'rename', 'rollback', 'convert')
   483 
   484 
   484     if not repo.local() or _parse(ui, sys.argv[1:])[0] in nokwcommands:
   485     def _getcmd():
       
   486         '''Simplified argument parsing as we are only interested in command.'''
       
   487         args = fancyopts(sys.argv[1:], commands.globalopts, {})
       
   488         if args:
       
   489             aliases, i = findcmd(ui, args[0], commands.table)
       
   490             return aliases[0]
       
   491 
       
   492     if not repo.local() or _getcmd() in nokwcommands:
   485         return
   493         return
   486 
   494 
   487     inc, exc = [], ['.hgtags']
   495     inc, exc = [], ['.hgtags']
   488     for pat, opt in ui.configitems('keyword'):
   496     for pat, opt in ui.configitems('keyword'):
   489         if opt != 'ignore':
   497         if opt != 'ignore':