hgkw/keyword.py
changeset 364 d935536a6abc
parent 358 3eff5c04034f
child 365 e99ace93ded0
equal deleted inserted replaced
358:3eff5c04034f 364:d935536a6abc
    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, filelog, localrepo
    83 from mercurial import commands, cmdutil, context, filelog, localrepo
    84 from mercurial import patch, revlog, templater, util
    84 from mercurial import patch, revlog, 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, tempfile, time
    87 import re, shutil, tempfile, time
    88 
    88 
    89 commands.optionalrepo += ' kwdemo'
    89 commands.optionalrepo += ' kwdemo'
   120             self.templates = dict(kwmaps)
   120             self.templates = dict(kwmaps)
   121         escaped = map(re.escape, self.templates.keys())
   121         escaped = map(re.escape, self.templates.keys())
   122         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   122         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
   123         self.re_kw = re.compile(kwpat)
   123         self.re_kw = re.compile(kwpat)
   124 
   124 
   125         templater.common_filters['utcdate'] = utcdate
   125         templatefilters.filters['utcdate'] = utcdate
   126         self.ct = cmdutil.changeset_templater(self.ui, self.repo,
   126         self.ct = cmdutil.changeset_templater(self.ui, self.repo,
   127                                               False, '', False)
   127                                               False, '', False)
   128 
   128 
   129     def substitute(self, path, data, node, subfunc):
   129     def substitute(self, path, data, node, subfunc):
   130         '''Obtains file's changenode if node not given,
   130         '''Obtains file's changenode if node not given,
   150             '''Substitutes keyword using corresponding template.'''
   150             '''Substitutes keyword using corresponding template.'''
   151             kw = mobj.group(1)
   151             kw = mobj.group(1)
   152             self.ct.use_template(self.templates[kw])
   152             self.ct.use_template(self.templates[kw])
   153             self.ui.pushbuffer()
   153             self.ui.pushbuffer()
   154             self.ct.show(changenode=node, root=self.repo.root, file=path)
   154             self.ct.show(changenode=node, root=self.repo.root, file=path)
   155             return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer()))
   155             ekw = templatefilters.firstline(self.ui.popbuffer())
       
   156             return '$%s: %s $' % (kw, ekw)
   156 
   157 
   157         return subfunc(kwsub, data)
   158         return subfunc(kwsub, data)
   158 
   159 
   159     def expand(self, path, data, node):
   160     def expand(self, path, data, node):
   160         '''Returns data with keywords expanded.'''
   161         '''Returns data with keywords expanded.'''