hgkw/keyword.py
branchstable
changeset 363 263b3b10c55f
parent 347 c912b8c3f3ff
child 371 c093df5fd251
equal deleted inserted replaced
362:3ea0cbaf3535 363:263b3b10c55f
    78 Expansions spanning more than one line and incremental expansions,
    78 Expansions spanning more than one line and incremental expansions,
    79 like CVS' $Log$, are not supported. A keyword template map
    79 like CVS' $Log$, are not supported. A keyword template map
    80 "Log = {desc}" expands to the first line of the changeset description.
    80 "Log = {desc}" expands to the first line of the changeset description.
    81 '''
    81 '''
    82 
    82 
    83 from mercurial import commands, cmdutil, context, dispatch, filelog
    83 from mercurial import commands, cmdutil, context, dispatch, filelog, revlog
    84 from mercurial import patch, localrepo, revlog, templater, util
    84 from mercurial import patch, localrepo, templater, templatefilters, util
    85 from mercurial.node import *
    85 from mercurial.node import *
    86 from mercurial.i18n import _
    86 from mercurial.i18n import _
    87 import re, shutil, sys, tempfile, time
    87 import re, shutil, sys, tempfile, time
    88 
    88 
    89 commands.optionalrepo += ' kwdemo'
    89 commands.optionalrepo += ' kwdemo'
   130             self.templates = dict(kwmaps)
   130             self.templates = dict(kwmaps)
   131         escaped = map(re.escape, self.templates.keys())
   131         escaped = map(re.escape, self.templates.keys())
   132         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   132         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   133         self.re_kw = re.compile(kwpat)
   133         self.re_kw = re.compile(kwpat)
   134 
   134 
   135         templater.common_filters['utcdate'] = utcdate
   135         templatefilters.filters['utcdate'] = utcdate
   136         self.ct = cmdutil.changeset_templater(self.ui, self.repo,
   136         self.ct = cmdutil.changeset_templater(self.ui, self.repo,
   137                                               False, '', False)
   137                                               False, '', False)
   138 
   138 
   139     def substitute(self, node, data, subfunc):
   139     def substitute(self, node, data, subfunc):
   140         '''Obtains file's changenode if commit node not given,
   140         '''Obtains file's changenode if commit node not given,
   149             '''Substitutes keyword using corresponding template.'''
   149             '''Substitutes keyword using corresponding template.'''
   150             kw = mobj.group(1)
   150             kw = mobj.group(1)
   151             self.ct.use_template(self.templates[kw])
   151             self.ct.use_template(self.templates[kw])
   152             self.ui.pushbuffer()
   152             self.ui.pushbuffer()
   153             self.ct.show(changenode=fnode, root=self.repo.root, file=self.path)
   153             self.ct.show(changenode=fnode, root=self.repo.root, file=self.path)
   154             return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer()))
   154             return '$%s: %s $' % (kw, templatefilters.firstline(
       
   155                 self.ui.popbuffer()))
   155 
   156 
   156         return subfunc(kwsub, data)
   157         return subfunc(kwsub, data)
   157 
   158 
   158     def expand(self, node, data):
   159     def expand(self, node, data):
   159         '''Returns data with keywords expanded.'''
   160         '''Returns data with keywords expanded.'''