hgext/keyword.py
changeset 5823 2a66138c5e7e
parent 5815 0637d97a8cb4
child 5824 b8e8bd3c82f6
--- a/hgext/keyword.py	Tue Jan 08 06:56:21 2008 +0300
+++ b/hgext/keyword.py	Wed Jan 09 05:18:50 2008 +0100
@@ -107,7 +107,7 @@
         self.ui = ui
         self.repo = repo
         self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
-        self.node = None
+        self.commitnode = None
         self.path = ''
 
         kwmaps = self.ui.configitems('keywordmaps')
@@ -124,18 +124,20 @@
                                               False, '', False)
 
     def substitute(self, node, data, subfunc):
-        '''Obtains node if missing, and calls given substitution function.'''
-        if not self.node:
+        '''Obtains file's changenode if commit node not given,
+        and calls given substitution function.'''
+        if self.commitnode:
+            fnode = self.commitnode
+        else:
             c = context.filectx(self.repo, self.path, fileid=node)
-            self.node = c.node()
+            fnode = c.node()
 
         def kwsub(mobj):
             '''Substitutes keyword using corresponding template.'''
             kw = mobj.group(1)
             self.ct.use_template(self.templates[kw])
             self.ui.pushbuffer()
-            self.ct.show(changenode=self.node,
-                         root=self.repo.root, file=self.path)
+            self.ct.show(changenode=fnode, root=self.repo.root, file=self.path)
             return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer()))
 
         return subfunc(kwsub, data)
@@ -228,16 +230,16 @@
     '''Overwrites selected files expanding/shrinking keywords.'''
     ctx = repo.changectx(node)
     mf = ctx.manifest()
-    if files is None:
-        notify = ui.debug # commit
+    if node is not None:   # commit
+        _kwtemplater.commitnode = node
         files = [f for f in ctx.files() if mf.has_key(f)]
-    else:
-        notify = ui.note  # kwexpand/kwshrink
+        notify = ui.debug
+    else:                  # kwexpand/kwshrink
+        notify = ui.note
     candidates = [f for f in files if _iskwfile(f, mf.linkf)]
     if candidates:
         candidates.sort()
         action = expand and 'expanding' or 'shrinking'
-        _kwtemplater.node = node or ctx.node()
         for f in candidates:
             fp = repo.file(f, kwmatch=True)
             data, kwfound = fp.kwctread(mf[f], expand)