hgkw/keyword.py
branchsolo-extension
changeset 76 d9c80746d727
parent 74 85c345cd495b
equal deleted inserted replaced
74:85c345cd495b 76:d9c80746d727
     1 # keyword.py - keyword expansion for mercurial
     1 # keyword.py - keyword expansion for mercurial
     2 # $Id$
     2 # $Id: keyword.py,v 85c345cd495b 2007-01-08 03:05:22 +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.
   227             # substitute keywords
   227             # substitute keywords
   228             for f in kwfmatches(ui, self, changed):
   228             for f in kwfmatches(ui, self, changed):
   229                 data = self.wfile(f).read()
   229                 data = self.wfile(f).read()
   230                 if not util.binary(data):
   230                 if not util.binary(data):
   231                     data, kwct = re_kw.subn(lambda m:
   231                     data, kwct = re_kw.subn(lambda m:
   232                             kwexpand(m, self, f, changeid=hex(n)),
   232                             kwexpand(m, self, f, changeid=hex(n)), data)
   233                             data)
       
   234                     if kwct:
   233                     if kwct:
   235                         ui.debug(_('overwriting %s expanding keywords\n' % f))
   234                         ui.debug(_('overwriting %s expanding keywords\n' % f))
   236                         self.wfile(f, 'w').write(data)
   235                         self.wfile(f, 'w').write(data)
   237 
   236 
   238             tr.close()
   237             tr.close()
   255 
   254 
   256         def read(self, node):
   255         def read(self, node):
   257             data = super(kwfilelog, self).read(node)
   256             data = super(kwfilelog, self).read(node)
   258             if not util.binary(data) and \
   257             if not util.binary(data) and \
   259                     kwfmatches(ui, self._repo, [self._path]):
   258                     kwfmatches(ui, self._repo, [self._path]):
   260                 ui.debug(_('expanding keywords in %s\n' % self._path))
       
   261                 return re_kw.sub(lambda m:
   259                 return re_kw.sub(lambda m:
   262                         kwexpand(m, self._repo, self._path,
   260                         kwexpand(m, self._repo, self._path,
   263                             fileid=node, filelog=self), data)
   261                             fileid=node, filelog=self), data)
   264             return data
   262             return data
   265 
   263 
   266         def cmp(self, node, text):
   264         def cmp(self, node, text):
   267             '''Removes keyword substitution for comparison.'''
   265             '''Removes keyword substitution for comparison.'''
   268             if not util.binary(text):
   266             if not util.binary(text) and \
       
   267                     kwfmatches(ui, self._repo, [self._path]):
   269                 text = re_kw.sub(r'$\1$', text)
   268                 text = re_kw.sub(r'$\1$', text)
   270             return super(kwfilelog, self).cmp(node, text)
   269             return super(kwfilelog, self).cmp(node, text)
   271 
   270 
   272     filelog.filelog = kwfilelog
   271     filelog.filelog = kwfilelog
   273     repo.__class__ = kwrepo
   272     repo.__class__ = kwrepo