hgkw/keyword.py
branchextension
changeset 34 3a79665dcbc3
parent 33 ebb39c6a1476
child 36 b3ace8cc5a33
equal deleted inserted replaced
33:ebb39c6a1476 34:3a79665dcbc3
     1 from mercurial import hg, filelog, revlog, context, util
     1 from mercurial import hg, filelog, revlog, context, util
     2 import re
     2 import os.path, re
     3 
     3 
     4 def reposetup(ui, repo):
     4 def reposetup(ui, repo):
     5     if not repo.local():
     5     if not repo.local():
     6         return
     6         return
     7 
     7 
    21             data = super(kwfilelog, self).read(node)
    21             data = super(kwfilelog, self).read(node)
    22             if (not util.binary(data) and
    22             if (not util.binary(data) and
    23                 self._repo.ui.config("keywords", "expand", True)):
    23                 self._repo.ui.config("keywords", "expand", True)):
    24                 c = context.filectx(self._repo, self._path, fileid=node,
    24                 c = context.filectx(self._repo, self._path, fileid=node,
    25                                      filelog=self)
    25                                      filelog=self)
    26                 def author(): return "$Author %s $" % c.user()
    26                 hgkw = '$Hg: %s,v %s %s %s $' % (
    27                 def date(): return "$Date %s $" % util.datestr(c.date())
    27                         os.path.basename(c.path()),
    28 
    28                         c.changectx(),
    29                 data = re.sub(r'\$Author\$', author(), data)
    29                         util.datestr(date=c.date(),
    30                 data = re.sub(r'\$Date\$', date(), data)
    30                             format=util.defaultdateformats[0]),
       
    31                         util.shortuser(c.user()))
       
    32                 data = data.replace('$Hg$', hgkw)
    31             return data
    33             return data
    32         def add(self, text, meta, tr, link, p1=None, p2=None):
    34         def add(self, text, meta, tr, link, p1=None, p2=None):
    33             if (not util.binary(text) and
    35             if (not util.binary(text) and
    34                    self._repo.ui.config("keywords", "remove", True)):
    36                    self._repo.ui.config("keywords", "remove", True)):
    35                 text = re.sub(r'\$Author[^\$]*\$', '$Author$', text)
    37                 text = re.sub(r'\$Hg[^$]*?\$', '$Hg$', text)
    36                 text = re.sub(r'\$Date[^\$]*\$', '$Date$', text)
       
    37             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
    38             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
    38 
    39 
    39     filelog.filelog = kwfilelog
    40     filelog.filelog = kwfilelog
    40     repo.__class__ = kwrepo
    41     repo.__class__ = kwrepo