No need to read changelog in show(); node mandatory arg for expand() kwmap-templates
authorChristian Ebert <blacktrash@gmx.net>
Mon, 15 Jan 2007 20:18:43 +0100
branchkwmap-templates
changeset 101 98a65d978098
parent 100 4f1129ddbdb8
child 102 393d6f8ea83c
No need to read changelog in show(); node mandatory arg for expand()
hgkw/keyword.py
--- a/hgkw/keyword.py	Mon Jan 15 19:41:18 2007 +0100
+++ b/hgkw/keyword.py	Mon Jan 15 20:18:43 2007 +0100
@@ -84,10 +84,9 @@
     Sets up keyword templates, corresponding keyword regex, and
     provides keyword expansion function.
     '''
-    def __init__(self, ui, repo, node=None):
+    def __init__(self, ui, repo):
         self.ui = ui
         self.repo = repo
-        self.node = node 
         templates = {}
         for k, v in self.ui.configitems('keywordmaps'):
             templates[k] = v
@@ -97,15 +96,12 @@
         self.t = cmdutil.changeset_templater(self.ui, self.repo,
                 False, '', False)
 
-    def expand(self, mobj, path, node=None):
-        self.node = self.node or node
+    def expand(self, mobj, path, node):
         kw = mobj.group(1)
         template = templater.parsestring(self.templates[kw], quoted=False)
         self.t.use_template(template)
         self.ui.pushbuffer()
-        self.t.show(changenode=self.node,
-                changes=self.repo.changelog.read(self.node),
-                root=self.repo.root, file=path)
+        self.t.show(changenode=node, root=self.repo.root, file=path)
         return '$%s: %s $' % (kw, self.ui.popbuffer())
 
 
@@ -144,7 +140,7 @@
                 c = context.filectx(self._repo, self._path,
                                     fileid=node, filelog=self)
                 return self.kwt.re_kw.sub(lambda m:
-                        self.kwt.expand(m, self._path, node=c.node()), data)
+                        self.kwt.expand(m, self._path, c.node()), data)
             return data
 
         def add(self, text, meta, tr, link, p1=None, p2=None):
@@ -197,11 +193,12 @@
     if not candidates:
         return
 
-    kwt = kwtemplater(ui, repo, node=bin(args['node']))
+    kwt = kwtemplater(ui, repo)
+    node = bin(args['node'])
     for f in candidates:
         data = repo.wfile(f).read()
         if not util.binary(data):
-            data, kwct = kwt.re_kw.subn(lambda m: kwt.expand(m, f), data)
+            data, kwct = kwt.re_kw.subn(lambda m: kwt.expand(m, f, node), data)
             if kwct:
                 ui.debug(_('overwriting %s expanding keywords\n' % f))
                 repo.wfile(f, 'w').write(data)