Make keyword do my hgkeyword; use basename again
add() needs only str.replace().
TODO:
Make even more compatible with cvs' $Id$? (date UTC, slashes)
Check config before reading.
And!:
Use config file patterns, in cooperation with pretxnkw.
This will expand keywords alread on commit!
from mercurial import hg, filelog, revlog, context, util
import os.path, re
def reposetup(ui, repo):
if not repo.local():
return
class kwrepo(repo.__class__):
def file(self, f):
if f[0] == '/':
f = f[1:]
return filelog.filelog(self.sopener, f, self, self.revlogversion)
class kwfilelog(filelog.filelog):
def __init__(self, opener, path, repo,
defversion=revlog.REVLOG_DEFAULT_VERSION):
super(kwfilelog, self).__init__(opener, path, defversion)
self._repo = repo
self._path = path
def read(self, node):
data = super(kwfilelog, self).read(node)
if (not util.binary(data) and
self._repo.ui.config("keywords", "expand", True)):
c = context.filectx(self._repo, self._path, fileid=node,
filelog=self)
hgkw = '$Hg: %s,v %s %s %s $' % (
os.path.basename(c.path()),
c.changectx(),
util.datestr(date=c.date(),
format=util.defaultdateformats[0]),
util.shortuser(c.user()))
data = data.replace('$Hg$', hgkw)
return data
def add(self, text, meta, tr, link, p1=None, p2=None):
if (not util.binary(text) and
self._repo.ui.config("keywords", "remove", True)):
text = re.sub(r'\$Hg[^$]*?\$', '$Hg$', text)
return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
filelog.filelog = kwfilelog
repo.__class__ = kwrepo