hgkw/keyword.py
branchsolo-extension
changeset 49 5acfe7dc3086
parent 48 59fedb6b41da
child 50 fe891f87a16c
equal deleted inserted replaced
48:59fedb6b41da 49:5acfe7dc3086
    37     pretxncommit =
    37     pretxncommit =
    38     pretxncommit.keyword = python:hgext.keyword.pretxnkw
    38     pretxncommit.keyword = python:hgext.keyword.pretxnkw
    39 '''
    39 '''
    40 
    40 
    41 from mercurial.i18n import _
    41 from mercurial.i18n import _
    42 from mercurial import commands, cmdutil, context, filelog, revlog, util
    42 from mercurial import cmdutil, commands, context, filelog, revlog, util
    43 import os.path, re, sys
    43 import os.path, re, sys
    44 
    44 
    45 # supported keywords for use in regexes
    45 # supported keywords for use in regexes
    46 hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source'
    46 hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source'
    47 
    47 
   103 
   103 
   104                         re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
   104                         re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
   105                         return re_kw.sub(kwexpander, data)
   105                         return re_kw.sub(kwexpander, data)
   106             return data
   106             return data
   107 
   107 
   108         def add(self, text, meta, tr, link, p1=None, p2=None):
   108         def size(self, rev):
   109             if (not util.binary(text) and
   109             '''Overrides filelog's size() to use kwfilelog.read().'''
   110                    self._repo.ui.config('keyword', 'remove', True)):
   110             node = self.node(rev)
   111                 re_kw = re.compile(r'\$(%s): [^$]+? \$' % hgkeywords)
   111             if self.renamed(node):
   112                 text = re_kw.sub(r'$\1$', text)
   112                 return len(self.read(node))
   113             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
   113             return revlog.size(self, rev)
       
   114 
       
   115         def cmp(self, node, text):
       
   116             '''Overrides filelog's cmp() to use kwfilelog.read().'''
       
   117             if self.renamed(node):
       
   118                 t2 = self.read(node)
       
   119                 return t2 != text
   114 
   120 
   115     filelog.filelog = kwfilelog
   121     filelog.filelog = kwfilelog
   116     repo.__class__ = kwrepo
   122     repo.__class__ = kwrepo
   117 
   123 
   118 
   124