Move context into kwtemplater.expand kwmap-templates
authorChristian Ebert <blacktrash@gmx.net>
Mon, 12 Feb 2007 00:38:47 +0100
branchkwmap-templates
changeset 139 0ea07bb56ff6
parent 138 bf8622c50309
child 140 cade80b9d83d
Move context into kwtemplater.expand Update kwtemplater doc string.
hgkw/keyword.py
--- a/hgkw/keyword.py	Sun Feb 11 19:51:22 2007 +0100
+++ b/hgkw/keyword.py	Mon Feb 12 00:38:47 2007 +0100
@@ -100,7 +100,7 @@
 class kwtemplater(object):
     '''
     Sets up keyword templates, corresponding keyword regex, and
-    provides keyword expansion function.
+    provides keyword substitution functions.
     '''
     def __init__(self, ui, repo):
         self.ui = ui
@@ -132,11 +132,13 @@
         keywordsub = templater.firstline(self.ui.popbuffer())
         return '$%s: %s $' % (kw, keywordsub)
 
-    def expand(self, path, node, data):
+    def expand(self, path, node, filelog, data):
         '''Returns data with expanded keywords.'''
         if util.binary(data):
             return data
-        return self.re_kw.sub(lambda m: self.kwsub(m, path, node), data)
+        c = context.filectx(self.repo, path, fileid=node, filelog=filelog)
+        cnode = c.node()
+        return self.re_kw.sub(lambda m: self.kwsub(m, path, cnode), data)
 
     def shrink(self, text):
         '''Returns text with all keyword substitutions removed.'''
@@ -227,9 +229,7 @@
             '''Substitutes keywords when reading filelog.'''
             data = super(kwfilelog, self).read(node)
             if self.kwt:
-                c = context.filectx(self._repo, self._path,
-                                    fileid=node, filelog=self)
-                data = self.kwt.expand(self._path, c.node(), data)
+                data = self.kwt.expand(self._path, node, self, data)
             return data
 
         def add(self, text, meta, tr, link, p1=None, p2=None):