Turn off debug while expanding
We don't need templates like file_add etc. as keywords a file specific.
Turning off debug avoids accidental expansion of such templates.
As a side effect it speeds up expansion when running hg --debug.
Functionality of _ctxnode now in new _substitute function.
--- a/hgkw/keyword.py Thu Oct 04 16:12:48 2007 +0200
+++ b/hgkw/keyword.py Fri Oct 05 14:52:39 2007 +0200
@@ -166,6 +166,7 @@
self.t = expand or None
self.path = path
self.node = node
+ self.debug = self.ui.debugflag
kwmaps = self.ui.configitems('keywordmaps')
if kwmaps: # override default templates
@@ -207,12 +208,6 @@
except AttributeError:
self.repo.dirstate.update(files, 'n')
- def _ctxnode(self, node):
- '''Obtains missing node from file context.'''
- if not self.node:
- c = context.filectx(self.repo, self.path, fileid=node)
- self.node = c.node()
-
def _kwsub(self, mobj):
'''Substitutes keyword using corresponding template.'''
kw = mobj.group(1)
@@ -222,12 +217,23 @@
keywordsub = templater.firstline(self.ui.popbuffer())
return '$%s: %s $' % (kw, keywordsub)
+ def _substitute(self, node, data, subfunc):
+ '''Obtains node if missing.
+ Ensures consistent templates regardless of ui.debugflag.
+ Calls given substitution function.'''
+ if not self.node:
+ c = context.filectx(self.repo, self.path, fileid=node)
+ self.node = c.node()
+ self.ui.debugflag = False
+ result = subfunc(self._kwsub, data)
+ self.ui.debugflag = self.debug
+ return result
+
def expand(self, node, data):
'''Returns data with keywords expanded.'''
if util.binary(data):
return data
- self._ctxnode(node)
- return self.re_kw.sub(self._kwsub, data)
+ return self._substitute(node, data, self.re_kw.sub)
def process(self, node, data):
'''Returns a tuple: data, count.
@@ -236,8 +242,7 @@
if util.binary(data):
return data, None
if self.t:
- self._ctxnode(node)
- return self.re_kw.subn(self._kwsub, data)
+ return self._substitute(node, data, self.re_kw.subn)
return data, self.re_kw.search(data)
def shrink(self, text):