hgkw/keyword.py
branchkwmap-templates
changeset 135 a4c748fc7e00
parent 134 f869c65156f7
child 136 5e9d6c57d679
equal deleted inserted replaced
134:f869c65156f7 135:a4c748fc7e00
    69 
    69 
    70 Configuration is done in the [keyword] and [keywordmaps] sections of
    70 Configuration is done in the [keyword] and [keywordmaps] sections of
    71 hgrc files.
    71 hgrc files.
    72 '''
    72 '''
    73 
    73 
    74 from mercurial.i18n import gettext as _
    74 try:
    75 # above line for backwards compatibility of standalone version
    75     from mercurial.demandload import * # stable
    76 from mercurial import cmdutil, templater, util
    76     from mercurial.i18n import gettext as _
    77 from mercurial import context, filelog, revlog
    77     demandload(globals(), 'mercurial:cmdutil,templater,util')
    78 import os.path, re, time
    78     demandload(globals(), 'mercurial:context,filelog,revlog')
       
    79     demandload(globals(), 'os.path re time')
       
    80 except ImportError: # demandimport
       
    81     from mercurial.i18n import _
       
    82     from mercurial import cmdutil, templater, util
       
    83     from mercurial import context, filelog, revlog
       
    84     import os.path, re, time
    79 
    85 
    80 deftemplates = {
    86 deftemplates = {
    81         'Revision': '{node|short}',
    87         'Revision': '{node|short}',
    82         'Author': '{author|user}',
    88         'Author': '{author|user}',
    83         'Date': '{date|utcdate}',
    89         'Date': '{date|utcdate}',
   101         self.repo = repo
   107         self.repo = repo
   102         self.templates = dict(ui.configitems('keywordmaps')) or deftemplates
   108         self.templates = dict(ui.configitems('keywordmaps')) or deftemplates
   103         self.re_kw = re.compile(r'\$(%s)[^$]*?\$' %
   109         self.re_kw = re.compile(r'\$(%s)[^$]*?\$' %
   104                 '|'.join(re.escape(k) for k in self.templates.keys()))
   110                 '|'.join(re.escape(k) for k in self.templates.keys()))
   105         templater.common_filters['utcdate'] = utcdate
   111         templater.common_filters['utcdate'] = utcdate
   106         self.t = cmdutil.changeset_templater(ui, repo, False, '', False)
   112         try:
       
   113             self.t = cmdutil.changeset_templater(ui, repo,
       
   114                     False, '', False)
       
   115         except TypeError:
       
   116             # depending on hg rev changeset_templater has extra "brinfo" arg
       
   117             self.t = cmdutil.changeset_templater(ui, repo,
       
   118                     False, None, '', False)
   107 
   119 
   108     def kwsub(self, mobj, path, node):
   120     def kwsub(self, mobj, path, node):
   109         '''Substitutes keyword using corresponding template.'''
   121         '''Substitutes keyword using corresponding template.'''
   110         kw = mobj.group(1)
   122         kw = mobj.group(1)
   111         template = templater.parsestring(self.templates[kw], quoted=False)
   123         template = templater.parsestring(self.templates[kw], quoted=False)