hgkw/keyword.py
branchextension
changeset 36 b3ace8cc5a33
parent 34 3a79665dcbc3
child 41 e1c539e1282b
equal deleted inserted replaced
35:a730c9d4ec05 36:b3ace8cc5a33
    15         def __init__(self, opener, path, repo,
    15         def __init__(self, opener, path, repo,
    16                      defversion=revlog.REVLOG_DEFAULT_VERSION):
    16                      defversion=revlog.REVLOG_DEFAULT_VERSION):
    17             super(kwfilelog, self).__init__(opener, path, defversion)
    17             super(kwfilelog, self).__init__(opener, path, defversion)
    18             self._repo = repo
    18             self._repo = repo
    19             self._path = path
    19             self._path = path
       
    20 
    20         def read(self, node):
    21         def read(self, node):
    21             data = super(kwfilelog, self).read(node)
    22             def gethgkw():
    22             if (not util.binary(data) and
       
    23                 self._repo.ui.config("keywords", "expand", True)):
       
    24                 c = context.filectx(self._repo, self._path, fileid=node,
    23                 c = context.filectx(self._repo, self._path, fileid=node,
    25                                      filelog=self)
    24                                      filelog=self)
    26                 hgkw = '$Hg: %s,v %s %s %s $' % (
    25                 filename = c.path()
    27                         os.path.basename(c.path()),
    26                 for pat, opt in self._repo.ui.configitems('keyword'):
    28                         c.changectx(),
    27                     if opt == 'expand':
    29                         util.datestr(date=c.date(),
    28                         mf = util.matcher(self._repo.root,
    30                             format=util.defaultdateformats[0]),
    29                                 '', [pat], [], [])[1]
    31                         util.shortuser(c.user()))
    30                         if mf(filename):
    32                 data = data.replace('$Hg$', hgkw)
    31                             return '$Hg: %s,v %s %s %s $' % (
       
    32                                     os.path.basename(filename),
       
    33                                     c.changectx(),
       
    34                                     util.datestr(date=c.date(),
       
    35                                         format=util.defaultdateformats[0]),
       
    36                                     util.shortuser(c.user())
       
    37                                     )
       
    38             data = super(kwfilelog, self).read(node)
       
    39             if not util.binary(data):
       
    40                 hgkw = gethgkw()
       
    41                 if hgkw:
       
    42                     data = data.replace('$Hg$', hgkw)
    33             return data
    43             return data
       
    44 
    34         def add(self, text, meta, tr, link, p1=None, p2=None):
    45         def add(self, text, meta, tr, link, p1=None, p2=None):
    35             if (not util.binary(text) and
    46             if (not util.binary(text) and
    36                    self._repo.ui.config("keywords", "remove", True)):
    47                    self._repo.ui.config('keyword', 'remove', True)):
    37                 text = re.sub(r'\$Hg[^$]*?\$', '$Hg$', text)
    48                 text = re.sub(r'\$Hg[^$]*?\$', '$Hg$', text)
    38             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
    49             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
    39 
    50 
    40     filelog.filelog = kwfilelog
    51     filelog.filelog = kwfilelog
    41     repo.__class__ = kwrepo
    52     repo.__class__ = kwrepo