keyword: enable all monkey patches using _kwtemplater at reposetup
authorChristian Ebert <blacktrash@gmx.net>
Sun, 10 Feb 2008 08:25:09 +0100
changeset 6081 beb775df5630fc48337f1eedf651663500983de8
parent 6080 4baad19c48014cf6aa331292e084a086a4dfafb6
child 6082 875b745996e81fce571785cb151a1188fce6fb16
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
keyword: enable all monkey patches using _kwtemplater at reposetup - no need for try-except block - underscore prefix for private methods - add doc strings
hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -110,40 +110,35 @@ def _kwpatchfile_init(self, ui, fname, m
     '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
     rejects or conflicts due to expanded keywords in working dir.'''
     _patchfile_init(self, ui, fname, missing=missing)
     if _kwtemplater.matcher(self.fname):
         # shrink keywords read from working dir
         kwshrunk = _kwtemplater.shrink(''.join(self.lines))
         self.lines = kwshrunk.splitlines(True)
 
+def _kwweb_changeset(web, req, tmpl):
+    '''Wraps webcommands.changeset turning off keyword expansion.'''
+    _kwtemplater.matcher = util.never
+    return web.changeset(tmpl, web.changectx(req))
+
+def _kwweb_filediff(web, req, tmpl):
+    '''Wraps webcommands.filediff turning off keyword expansion.'''
+    _kwtemplater.matcher = util.never
+    return web.filediff(tmpl, web.filectx(req))
+
 def _kwdispatch_parse(ui, args):
     '''Monkeypatch dispatch._parse to obtain
     current command and command options (global _cmd, _cmdoptions).'''
     global _cmd, _cmdoptions
     _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args)
     return _cmd, func, args, options, _cmdoptions
 
-def kwweb_changeset(web, req, tmpl):
-    try:
-        _kwtemplater.matcher = util.never
-    except AttributeError:
-        pass
-    return web.changeset(tmpl, web.changectx(req))
-
-def kwweb_filediff(web, req, tmpl):
-    try:
-        _kwtemplater.matcher = util.never
-    except AttributeError:
-        pass
-    return web.filediff(tmpl, web.filectx(req))
-
+# dispatch._parse is run before reposetup, so wrap it here
 dispatch._parse = _kwdispatch_parse
-webcommands.changeset = webcommands.rev = kwweb_changeset
-webcommands.filediff = webcommands.diff = kwweb_filediff
 
 
 class kwtemplater(object):
     '''
     Sets up keyword templates, corresponding keyword regex, and
     provides keyword substitution functions.
     '''
     templates = {
@@ -522,16 +517,18 @@ def reposetup(ui, repo):
                     _overwrite(ui, self, node=node)
                     repo.hook('commit', node=node, parent1=_p1, parent2=_p2)
                 return node
             finally:
                 del wlock, lock
 
     repo.__class__ = kwrepo
     patch.patchfile.__init__ = _kwpatchfile_init
+    webcommands.changeset = webcommands.rev = _kwweb_changeset
+    webcommands.filediff = webcommands.diff = _kwweb_filediff
 
 
 cmdtable = {
     'kwdemo':
         (demo,
          [('d', 'default', None, _('show default keyword template maps')),
           ('f', 'rcfile', [], _('read maps from rcfile'))],
          _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')),