hgkw/keyword.py
changeset 265 1b6b7835e3f9
parent 264 7c637046c0e2
child 266 50ce25f8c676
--- a/hgkw/keyword.py	Thu Oct 11 13:10:33 2007 +0200
+++ b/hgkw/keyword.py	Sat Oct 13 15:01:55 2007 +0200
@@ -267,8 +267,8 @@
         notify = (self.ui.note, self.ui.debug)[commit]
         overwritten = []
         for f in candidates:
-            fp = self.repo.file(f, kwexp=expand, kwcnt=True, kwmatch=True)
-            data, kwfound = fp.read(man[f])
+            fp = self.repo.file(f, kwexp=expand, kwmatch=True)
+            data, kwfound = fp.kwctread(man[f])
             if kwfound:
                 notify(_('overwriting %s %s keywords\n') % (f, action))
                 self._wwrite(f, data, man)
@@ -280,19 +280,20 @@
     Subclass of filelog to hook into its read, add, cmp methods.
     Keywords are "stored" unexpanded, and processed on reading.
     '''
-    def __init__(self, opener, path, kwtemplater, kwcnt):
+    def __init__(self, opener, path, kwtemplater):
         super(kwfilelog, self).__init__(opener, path)
         self.kwtemplater = kwtemplater
-        self.kwcnt = kwcnt
+
+    def kwctread(self, node):
+        '''Reads expanding and counting keywords
+        (only called from kwtemplater.overwrite).'''
+        data = super(kwfilelog, self).read(node)
+        return self.kwtemplater.process(node, data)
 
     def read(self, node):
-        '''Passes data through kwemplater methods for
-        either unconditional keyword expansion
-        or counting of keywords and substitution.'''
+        '''Expands keywords when reading filelog.'''
         data = super(kwfilelog, self).read(node)
-        if not self.kwcnt:
-            return self.kwtemplater.expand(node, data)
-        return self.kwtemplater.process(node, data)
+        return self.kwtemplater.expand(node, data)
 
     def add(self, text, meta, tr, link, p1=None, p2=None):
         '''Removes keyword substitutions when adding to filelog.'''
@@ -487,12 +488,12 @@
     ui.kwfmatcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
 
     class kwrepo(repo.__class__):
-        def file(self, f, kwexp=True, kwcnt=False, kwmatch=False):
+        def file(self, f, kwexp=True, kwmatch=False):
             if f[0] == '/':
                 f = f[1:]
             if kwmatch or ui.kwfmatcher(f):
                 kwt = kwtemplater(ui, self, kwexp, path=f)
-                return kwfilelog(self.sopener, f, kwt, kwcnt)
+                return kwfilelog(self.sopener, f, kwt)
             return filelog.filelog(self.sopener, f)
 
         def _commit(self, files, text, user, date, match, force, lock, wlock,