Make changes from last cset 474b415433a1 available to 0.9.3 0.9.3-compat
authorChristian Ebert <blacktrash@gmx.net>
Mon, 08 Jan 2007 13:07:52 +0100
branch0.9.3-compat
changeset 79 33eb5aa6f6e1
parent 77 048153ccf040
child 127 f88ecc1a41fa
Make changes from last cset 474b415433a1 available to 0.9.3
hgkw/keyword.py
--- a/hgkw/keyword.py	Mon Jan 08 05:47:52 2007 +0100
+++ b/hgkw/keyword.py	Mon Jan 08 13:07:52 2007 +0100
@@ -1,5 +1,5 @@
 # keyword.py - keyword expansion for mercurial
-# $Id: keyword.py,v c4daf4753ed3 2007-01-08 03:08:24 +0100 blacktrash $
+# $Id$
 
 '''keyword expansion hack against the grain of a DSCM
 
@@ -242,25 +242,40 @@
             return n
 
     class kwfilelog(filelog.filelog):
+        '''
+        Superclass over filelog to customize it's read, add, cmp methods.
+        Keywords are "stored" unexpanded, and expanded on reading.
+        '''
         def __init__(self, opener, path, repo,
                      defversion=revlog.REVLOG_DEFAULT_VERSION):
             super(kwfilelog, self).__init__(opener, path, defversion)
             self._repo = repo
             self._path = path
 
+        def iskwcandidate(self, data):
+            '''Decides whether to act on keywords.'''
+            return (kwfmatches(ui, self._repo, [self._path])
+                    and not util.binary(data))
+
         def read(self, node):
+            '''Substitutes keywords when reading filelog.'''
             data = super(kwfilelog, self).read(node)
-            if not util.binary(data) and \
-                    kwfmatches(ui, self._repo, [self._path]):
+            if self.iskwcandidate(data):
                 return re_kw.sub(lambda m:
                         kwexpand(m, self._repo, self._path,
                             fileid=node, filelog=self), data)
             return data
 
+        def add(self, text, meta, tr, link, p1=None, p2=None):
+            '''Removes keyword substitutions when adding to filelog.'''
+            if self.iskwcandidate(text):
+                text = re_kw.sub(r'$\1$', text)
+            return super(kwfilelog, self).add(text,
+                    meta, tr, link, p1=None, p2=None)
+
         def cmp(self, node, text):
-            '''Removes keyword substitution for comparison.'''
-            if not util.binary(text) and \
-                    kwfmatches(ui, self._repo, [self._path]):
+            '''Removes keyword substitutions for comparison.'''
+            if self.iskwcandidate(text):
                 text = re_kw.sub(r'$\1$', text)
             return super(kwfilelog, self).cmp(node, text)