1 # keyword.py - $Keyword$ expansion for Mercurial |
1 # keyword.py - $Keyword$ expansion for Mercurial |
2 # |
2 # |
3 # Copyright 2007 Christian Ebert <blacktrash@gmx.net> |
3 # Copyright 2007, 2008 Christian Ebert <blacktrash@gmx.net> |
4 # |
4 # |
5 # This software may be used and distributed according to the terms |
5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. |
6 # of the GNU General Public License, incorporated herein by reference. |
7 # |
7 # |
8 # $Id$ |
8 # $Id$ |
150 return data |
150 return data |
151 return self.substitute(node, data, self.re_kw.sub) |
151 return self.substitute(node, data, self.re_kw.sub) |
152 |
152 |
153 def process(self, node, data, expand): |
153 def process(self, node, data, expand): |
154 '''Returns a tuple: data, count. |
154 '''Returns a tuple: data, count. |
155 Count is number of keywords/keyword substitutions, indicates |
155 Count is number of keywords/keyword substitutions, |
156 to caller whether to act on file containing data. |
156 telling caller whether to act on file containing data.''' |
157 Keywords in data are expanded, if templater was initialized.''' |
|
158 if util.binary(data): |
157 if util.binary(data): |
159 return data, None |
158 return data, None |
160 if expand: |
159 if expand: |
161 return self.substitute(node, data, self.re_kw.subn) |
160 return self.substitute(node, data, self.re_kw.subn) |
162 return data, self.re_kw.search(data) |
161 return data, self.re_kw.search(data) |
175 def __init__(self, opener, path): |
174 def __init__(self, opener, path): |
176 super(kwfilelog, self).__init__(opener, path) |
175 super(kwfilelog, self).__init__(opener, path) |
177 _kwtemplater.path = path |
176 _kwtemplater.path = path |
178 |
177 |
179 def kwctread(self, node, expand): |
178 def kwctread(self, node, expand): |
180 '''Reads expanding and counting keywords |
179 '''Reads expanding and counting keywords, called from _overwrite.''' |
181 (only called from kwtemplater.overwrite).''' |
|
182 data = super(kwfilelog, self).read(node) |
180 data = super(kwfilelog, self).read(node) |
183 return _kwtemplater.process(node, data, expand) |
181 return _kwtemplater.process(node, data, expand) |
184 |
182 |
185 def read(self, node): |
183 def read(self, node): |
186 '''Expands keywords when reading filelog.''' |
184 '''Expands keywords when reading filelog.''' |