[PATCH 2 of 2] keyword: get changectx via linkrev

Christian Ebert blacktrash at gmx.net
Fri Nov 14 15:41:41 CST 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1226698144 -3600
# Node ID b91737072d59bb21ba8c2f784d175ae55985648b
# Parent  b556a8831c9173b48ad83d5a4bcf345c2f0038e9
keyword: get changectx via linkrev

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -150,10 +150,16 @@
             return '$%s: %s $' % (kw, ekw)
         return subfunc(kwsub, data)
 
-    def expand(self, path, node, data):
+    def getctx(self, flog, node):
+        '''Obtains change context via linkrev.'''
+        # used by kwfilelog.read and kwexpand
+        linkrev = flog.linkrev(flog.rev(node))
+        return self.repo[linkrev]
+
+    def expand(self, path, flog, node, data):
         '''Returns data with keywords expanded.'''
         if not self.restrict and self.matcher(path) and not util.binary(data):
-            ctx = self.repo.filectx(path, fileid=node).changectx()
+            ctx = self.getctx(flog, node)
             return self.substitute(data, path, ctx, self.re_kw.sub)
         return data
 
@@ -183,7 +189,7 @@
                     continue
                 if expand:
                     if node is None:
-                        ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
+                        ctx = self.getctx(fp, mf[f])
                     data, found = self.substitute(data, f, ctx,
                                                   self.re_kw.subn)
                 else:
@@ -230,7 +236,7 @@
     def read(self, node):
         '''Expands keywords when reading filelog.'''
         data = super(kwfilelog, self).read(node)
-        return self.kwt.expand(self.path, node, data)
+        return self.kwt.expand(self.path, self, node, data)
 
     def add(self, text, meta, tr, link, p1=None, p2=None):
         '''Removes keyword substitutions when adding to filelog.'''


More information about the Mercurial-devel mailing list