[PATCH] keyword: avoid repeated context retrieval on commit

Christian Ebert blacktrash at gmx.net
Fri Nov 14 10:53:32 CST 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1226681182 -3600
# Node ID 65472844ddce26a78046e5cdee3580a1334fc91e
# Parent  d9e9dd2b00fbaf9469d847948232f50b70423511
keyword: avoid repeated context retrieval on commit

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -139,19 +139,19 @@
         self.ct = cmdutil.changeset_templater(self.ui, self.repo,
                                               False, '', False)
 
-    def getnode(self, path, fnode):
+    def getkctx(self, path, fnode):
         '''Derives changenode from file path and filenode.'''
         # used by kwfilelog.read and kwexpand
         c = self.repo.filectx(path, fileid=fnode)
-        return c.node()
+        return self.repo[c.node()]
 
-    def substitute(self, data, path, node, subfunc):
+    def substitute(self, data, path, ctx, subfunc):
         '''Replaces keywords in data with expanded template.'''
         def kwsub(mobj):
             kw = mobj.group(1)
             self.ct.use_template(self.templates[kw])
             self.ui.pushbuffer()
-            self.ct.show(self.repo[node], root=self.repo.root, file=path)
+            self.ct.show(ctx, root=self.repo.root, file=path)
             ekw = templatefilters.firstline(self.ui.popbuffer())
             return '$%s: %s $' % (kw, ekw)
         return subfunc(kwsub, data)
@@ -159,8 +159,8 @@
     def expand(self, path, node, data):
         '''Returns data with keywords expanded.'''
         if not self.restrict and self.matcher(path) and not util.binary(data):
-            changenode = self.getnode(path, node)
-            return self.substitute(data, path, changenode, self.re_kw.sub)
+            kctx = self.getkctx(path, node)
+            return self.substitute(data, path, kctx, self.re_kw.sub)
         return data
 
     def iskwfile(self, path, flagfunc):
@@ -190,8 +190,8 @@
                 if util.binary(data):
                     continue
                 if expand:
-                    changenode = node or self.getnode(f, mf[f])
-                    data, found = self.substitute(data, f, changenode,
+                    kctx = node and ctx or self.getkctx(f, mf[f])
+                    data, found = self.substitute(data, f, kctx,
                                                   self.re_kw.subn)
                 else:
                     found = self.re_kw.search(data)


More information about the Mercurial-devel mailing list