hgkw/keyword.py
changeset 398 257da73e109f
parent 396 c5dfb272ff4f
child 401 05d0c3e4efdc
equal deleted inserted replaced
396:c5dfb272ff4f 398:257da73e109f
    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, revlog
    83 from mercurial import commands, cmdutil, context, dispatch, filelog, revlog
    84 from mercurial import patch, localrepo, templater, templatefilters, util
    84 from mercurial import patch, localrepo, templater, templatefilters, util
       
    85 from mercurial.hgweb import webcommands
    85 from mercurial.node import *
    86 from mercurial.node import *
    86 from mercurial.i18n import _
    87 from mercurial.i18n import _
    87 import re, shutil, tempfile, time
    88 import re, shutil, tempfile, time
    88 
    89 
    89 commands.optionalrepo += ' kwdemo'
    90 commands.optionalrepo += ' kwdemo'
   114     if _kwtemplater.matcher(self.fname):
   115     if _kwtemplater.matcher(self.fname):
   115         # shrink keywords read from working dir
   116         # shrink keywords read from working dir
   116         kwshrunk = _kwtemplater.shrink(''.join(self.lines))
   117         kwshrunk = _kwtemplater.shrink(''.join(self.lines))
   117         self.lines = kwshrunk.splitlines(True)
   118         self.lines = kwshrunk.splitlines(True)
   118 
   119 
       
   120 def _kwweb_changeset(web, req, tmpl):
       
   121     '''Wraps webcommands.changeset turning off keyword expansion.'''
       
   122     _kwtemplater.matcher = util.never
       
   123     return web.changeset(tmpl, web.changectx(req))
       
   124 
       
   125 def _kwweb_filediff(web, req, tmpl):
       
   126     '''Wraps webcommands.filediff turning off keyword expansion.'''
       
   127     _kwtemplater.matcher = util.never
       
   128     return web.filediff(tmpl, web.filectx(req))
       
   129 
   119 def _kwdispatch_parse(ui, args):
   130 def _kwdispatch_parse(ui, args):
   120     '''Monkeypatch dispatch._parse to obtain
   131     '''Monkeypatch dispatch._parse to obtain
   121     current command and command options (global _cmd, _cmdoptions).'''
   132     current command and command options (global _cmd, _cmdoptions).'''
   122     global _cmd, _cmdoptions
   133     global _cmd, _cmdoptions
   123     _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args)
   134     _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args)
   124     return _cmd, func, args, options, _cmdoptions
   135     return _cmd, func, args, options, _cmdoptions
   125 
   136 
       
   137 # dispatch._parse is run before reposetup, so wrap it here
   126 dispatch._parse = _kwdispatch_parse
   138 dispatch._parse = _kwdispatch_parse
   127 
   139 
   128 
   140 
   129 class kwtemplater(object):
   141 class kwtemplater(object):
   130     '''
   142     '''
   510             finally:
   522             finally:
   511                 del wlock, lock
   523                 del wlock, lock
   512 
   524 
   513     repo.__class__ = kwrepo
   525     repo.__class__ = kwrepo
   514     patch.patchfile.__init__ = _kwpatchfile_init
   526     patch.patchfile.__init__ = _kwpatchfile_init
       
   527     webcommands.changeset = webcommands.rev = _kwweb_changeset
       
   528     webcommands.filediff = webcommands.diff = _kwweb_filediff
   515 
   529 
   516 
   530 
   517 cmdtable = {
   531 cmdtable = {
   518     'kwdemo':
   532     'kwdemo':
   519         (demo,
   533         (demo,