hgkw/keyword.py
branch0.9.3-compat
changeset 77 048153ccf040
parent 75 c4daf4753ed3
child 78 474b415433a1
equal deleted inserted replaced
75:c4daf4753ed3 77:048153ccf040
     1 # keyword.py - keyword expansion for mercurial
     1 # keyword.py - keyword expansion for mercurial
     2 # $Id$
     2 # $Id: keyword.py,v c4daf4753ed3 2007-01-08 03:08:24 +0100 blacktrash $
     3 
     3 
     4 '''keyword expansion hack against the grain of a DSCM
     4 '''keyword expansion hack against the grain of a DSCM
     5 
     5 
     6 This extension lets you expand RCS/CVS-like keywords in a Mercurial
     6 This extension lets you expand RCS/CVS-like keywords in a Mercurial
     7 repository.
     7 repository.
   223             # substitute keywords
   223             # substitute keywords
   224             for f in kwfmatches(ui, self, changed):
   224             for f in kwfmatches(ui, self, changed):
   225                 data = self.wfile(f).read()
   225                 data = self.wfile(f).read()
   226                 if not util.binary(data):
   226                 if not util.binary(data):
   227                     data, kwct = re_kw.subn(lambda m:
   227                     data, kwct = re_kw.subn(lambda m:
   228                             kwexpand(m, self, f, changeid=hex(n)),
   228                             kwexpand(m, self, f, changeid=hex(n)), data)
   229                             data)
       
   230                     if kwct:
   229                     if kwct:
   231                         ui.debug(_('overwriting %s expanding keywords\n' % f))
   230                         ui.debug(_('overwriting %s expanding keywords\n' % f))
   232                         self.wfile(f, 'w').write(data)
   231                         self.wfile(f, 'w').write(data)
   233 
   232 
   234             tr.close()
   233             tr.close()
   251 
   250 
   252         def read(self, node):
   251         def read(self, node):
   253             data = super(kwfilelog, self).read(node)
   252             data = super(kwfilelog, self).read(node)
   254             if not util.binary(data) and \
   253             if not util.binary(data) and \
   255                     kwfmatches(ui, self._repo, [self._path]):
   254                     kwfmatches(ui, self._repo, [self._path]):
   256                 ui.debug(_('expanding keywords in %s\n' % self._path))
       
   257                 return re_kw.sub(lambda m:
   255                 return re_kw.sub(lambda m:
   258                         kwexpand(m, self._repo, self._path,
   256                         kwexpand(m, self._repo, self._path,
   259                             fileid=node, filelog=self), data)
   257                             fileid=node, filelog=self), data)
   260             return data
   258             return data
   261 
   259 
   262         def cmp(self, node, text):
   260         def cmp(self, node, text):
   263             '''Removes keyword substitution for comparison.'''
   261             '''Removes keyword substitution for comparison.'''
   264             if not util.binary(text):
   262             if not util.binary(text) and \
       
   263                     kwfmatches(ui, self._repo, [self._path]):
   265                 text = re_kw.sub(r'$\1$', text)
   264                 text = re_kw.sub(r'$\1$', text)
   266             return super(kwfilelog, self).cmp(node, text)
   265             return super(kwfilelog, self).cmp(node, text)
   267 
   266 
   268     filelog.filelog = kwfilelog
   267     filelog.filelog = kwfilelog
   269     repo.__class__ = kwrepo
   268     repo.__class__ = kwrepo