hgkw/keyword.py
changeset 756 c39a201b2b7f
parent 754 6c99007688ce
child 757 fdbfecffd95b
equal deleted inserted replaced
755:53df72b60f06 756:c39a201b2b7f
    50 
    50 
    51 For [keywordmaps] template mapping and expansion demonstration and
    51 For [keywordmaps] template mapping and expansion demonstration and
    52 control run :hg:`kwdemo`. See :hg:`help templates` for a list of
    52 control run :hg:`kwdemo`. See :hg:`help templates` for a list of
    53 available templates and filters.
    53 available templates and filters.
    54 
    54 
    55 An additional date template filter {date|utcdate} is provided. It
    55 Three additional date template filters are provided::
    56 returns a date like "2006/09/18 15:13:13".
    56 
       
    57     utcdate      "2006/09/18 15:13:13"
       
    58     svnutcdate   "2006-09-18 15:13:13Z"
       
    59     svnisodate   "2006-09-18 08:13:13 -700 (Mon, 18 Sep 2006)"
    57 
    60 
    58 The default template mappings (view with :hg:`kwdemo -d`) can be
    61 The default template mappings (view with :hg:`kwdemo -d`) can be
    59 replaced with customized keywords and templates. Again, run
    62 replaced with customized keywords and templates. Again, run
    60 :hg:`kwdemo` to control the results of your config changes.
    63 :hg:`kwdemo` to control the results of your config changes.
    61 
    64 
    92 # commands using dorecord
    95 # commands using dorecord
    93 recordcommands = 'record qrecord'
    96 recordcommands = 'record qrecord'
    94 # names of extensions using dorecord
    97 # names of extensions using dorecord
    95 recordextensions = 'record'
    98 recordextensions = 'record'
    96 
    99 
    97 # provide cvs-like UTC date filter
   100 # date like in cvs' $Date
    98 utcdate = lambda x: util.datestr((x[0], 0), '%Y/%m/%d %H:%M:%S')
   101 utcdate = lambda x: util.datestr((x[0], 0), '%Y/%m/%d %H:%M:%S')
       
   102 # date like in svn's $Date
       
   103 svnisodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
       
   104 # date like in svn's $Id
       
   105 svnutcdate = lambda x: util.datestr((x[0], 0), '%Y-%m-%d %H:%M:%SZ')
    99 
   106 
   100 # make keyword tools accessible
   107 # make keyword tools accessible
   101 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
   108 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
   102 
   109 
   103 
   110 
   133         escaped = map(re.escape, self.templates.keys())
   140         escaped = map(re.escape, self.templates.keys())
   134         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   141         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   135         self.re_kw = re.compile(kwpat)
   142         self.re_kw = re.compile(kwpat)
   136 
   143 
   137         templatefilters.filters['utcdate'] = utcdate
   144         templatefilters.filters['utcdate'] = utcdate
       
   145         templatefilters.filters['svnisodate'] = svnisodate
       
   146         templatefilters.filters['svnutcdate'] = svnutcdate
   138 
   147 
   139     def substitute(self, data, path, ctx, subfunc):
   148     def substitute(self, data, path, ctx, subfunc):
   140         '''Replaces keywords in data with expanded template.'''
   149         '''Replaces keywords in data with expanded template.'''
   141         def kwsub(mobj):
   150         def kwsub(mobj):
   142             kw = mobj.group(1)
   151             kw = mobj.group(1)