Unexpanded storage hopefully covered now by adding kwfilelog.add (again!) solo-extension
authorChristian Ebert <blacktrash@gmx.net>
Mon, 08 Jan 2007 12:54:31 +0100
branchsolo-extension
changeset 78 474b415433a1
parent 76 d9c80746d727
child 80 cee5fef33cf8
Unexpanded storage hopefully covered now by adding kwfilelog.add (again!) All filelog methods that act on text/data should be consistent. Principle: read expanded kw's; unexpanded kw's for "internal" workings. kwfilelog.iskwcandidate() to check whether keyword action required. More doc.
hgkw/keyword.py
--- a/hgkw/keyword.py	Mon Jan 08 05:40:34 2007 +0100
+++ b/hgkw/keyword.py	Mon Jan 08 12:54:31 2007 +0100
@@ -1,5 +1,5 @@
 # keyword.py - keyword expansion for mercurial
-# $Id: keyword.py,v 85c345cd495b 2007-01-08 03:05:22 +0100 blacktrash $
+# $Id$
 
 '''keyword expansion hack against the grain of a DSCM
 
@@ -246,25 +246,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)