[PATCH 2 of 2] keyword: function to look up changectx for expansion

Christian Ebert blacktrash at gmx.net
Tue Oct 26 10:44:45 CDT 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1288107811 -3600
# Branch stable
# Node ID 8332e6562089e23f074b843103851c23259e76e4
# Parent  3f3ba56cc8965ce27870f5d2844278be1e74c086
keyword: function to look up changectx for expansion

Similarly rename variable in kwtemplater.overwrite().

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -205,10 +205,14 @@
             return '$%s: %s $' % (kw, ekw)
         return subfunc(kwsub, data)
 
+    def linkctx(self, path, fileid):
+        '''Similar to filelog.linkrev, but returns a changectx.'''
+        return self.repo.filectx(path, fileid=fileid).changectx()
+
     def expand(self, path, node, data):
         '''Returns data with keywords expanded.'''
         if not self.restrict and self.match(path) and not util.binary(data):
-            ctx = self.repo.filectx(path, fileid=node).changectx()
+            ctx = self.linkctx(path, node)
             return self.substitute(data, path, ctx, self.rekw().sub)
         return data
 
@@ -226,7 +230,7 @@
         kwcmd = self.restrict and lookup # kwexpand/kwshrink
         if self.restrict or expand and lookup:
             mf = ctx.manifest()
-        fctx = ctx
+        lctx = ctx
         re_kw = (self.restrict or rekw) and self.rekw() or self.rekwexp()
         msg = (expand and _('overwriting %s expanding keywords\n')
                or _('overwriting %s shrinking keywords\n'))
@@ -239,8 +243,8 @@
                 continue
             if expand:
                 if lookup:
-                    fctx = self.repo.filectx(f, fileid=mf[f]).changectx()
-                data, found = self.substitute(data, f, fctx, re_kw.subn)
+                    lctx = self.linkctx(f, mf[f])
+                data, found = self.substitute(data, f, lctx, re_kw.subn)
             elif self.restrict:
                 found = re_kw.search(data)
             else:


More information about the Mercurial-devel mailing list