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$ |
261 return data |
261 return data |
262 return self.substitute(node, data, self.re_kw.sub) |
262 return self.substitute(node, data, self.re_kw.sub) |
263 |
263 |
264 def process(self, node, data, expand): |
264 def process(self, node, data, expand): |
265 '''Returns a tuple: data, count. |
265 '''Returns a tuple: data, count. |
266 Count is number of keywords/keyword substitutions, indicates |
266 Count is number of keywords/keyword substitutions, |
267 to caller whether to act on file containing data. |
267 telling caller whether to act on file containing data.''' |
268 Keywords in data are expanded, if templater was initialized.''' |
|
269 if util.binary(data): |
268 if util.binary(data): |
270 return data, None |
269 return data, None |
271 if expand: |
270 if expand: |
272 return self.substitute(node, data, self.re_kw.subn) |
271 return self.substitute(node, data, self.re_kw.subn) |
273 return data, self.re_kw.search(data) |
272 return data, self.re_kw.search(data) |
286 def __init__(self, opener, path): |
285 def __init__(self, opener, path): |
287 super(kwfilelog, self).__init__(opener, path) |
286 super(kwfilelog, self).__init__(opener, path) |
288 _kwtemplater.path = path |
287 _kwtemplater.path = path |
289 |
288 |
290 def kwctread(self, node, expand): |
289 def kwctread(self, node, expand): |
291 '''Reads expanding and counting keywords |
290 '''Reads expanding and counting keywords, called from _overwrite.''' |
292 (only called from kwtemplater.overwrite).''' |
|
293 data = super(kwfilelog, self).read(node) |
291 data = super(kwfilelog, self).read(node) |
294 return _kwtemplater.process(node, data, expand) |
292 return _kwtemplater.process(node, data, expand) |
295 |
293 |
296 def read(self, node): |
294 def read(self, node): |
297 '''Expands keywords when reading filelog.''' |
295 '''Expands keywords when reading filelog.''' |