Merge with stable
authorChristian Ebert <blacktrash@gmx.net>
Fri, 14 Nov 2008 23:01:00 +0100
changeset 506 7d5c8c734b74
parent 503 5cf987b0f3a1 (current diff)
parent 505 a93358a05b80 (diff)
child 507 51296bd1652f
Merge with stable
--- a/hgkw/keyword.py	Mon Nov 03 23:16:39 2008 +0100
+++ b/hgkw/keyword.py	Fri Nov 14 23:01:00 2008 +0100
@@ -141,19 +141,13 @@
         self.ct = cmdutil.changeset_templater(self.ui, self.repo,
                                               False, '', False)
 
-    def getnode(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()
-
-    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(changenode=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)
@@ -161,8 +155,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)
+            ctx = self.repo.filectx(path, fileid=node).changectx()
+            return self.substitute(data, path, ctx, self.re_kw.sub)
         return data
 
     def iskwfile(self, path, flagfunc):
@@ -179,7 +173,7 @@
             files = [f for f in ctx.files() if f in mf]
             notify = self.ui.debug
         else:                    # kwexpand/kwshrink
-            ctx = self.repo['.']
+            ctx = self.repo[None]
             mf = ctx.manifest()
             notify = self.ui.note
         candidates = [f for f in files if self.iskwfile(f, ctx.flags)]
@@ -192,8 +186,9 @@
                 if util.binary(data):
                     continue
                 if expand:
-                    changenode = node or self.getnode(f, mf[f])
-                    data, found = self.substitute(data, f, changenode,
+                    if node is None:
+                        ctx = self.repo.filectx(f, fileid=mf[f]).changectx()
+                    data, found = self.substitute(data, f, ctx,
                                                   self.re_kw.subn)
                 else:
                     found = self.re_kw.search(data)