[PATCH] keyword: get changectx via linkrev (w/o extra func)

Christian Ebert blacktrash at gmx.net
Sat Nov 15 01:14:38 CST 2008


This patch provides a rather clear choice between the 2 methods
to obtain the changectx. At least for archiving purposes ;-)

Matt's proposal looked enticing as we already have the filelog,
but I can't judge which alternative really[tm] is the better one.
This one /looks/ even a bit shorter. But if the way via filectx
is actually faster ...


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1226732507 -3600
# Node ID 2b3f939c07ded8f1a09a0c771ff44016f9c6e94c
# Parent  8dde275680d8b60277be02be47f61167cf70f022
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,10 @@
             return '$%s: %s $' % (kw, ekw)
         return subfunc(kwsub, data)
-    def expand(self, path, node, data):
+    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.repo[flog.linkrev(flog.rev(node))]
             return self.substitute(data, path, ctx, self.re_kw.sub)
         return data
@@ -183,7 +183,7 @@
                 if expand:
                     if node is None:
-                        ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
+                        ctx = self.repo[fp.linkrev(fp.rev(mf[f]))]
                     data, found = self.substitute(data, f, ctx,
@@ -230,7 +230,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