Attachment 'keyword.py'
Download 1 from mercurial import hg, filelog, revlog, context, util
2 import re
3
4 def reposetup(ui, repo):
5 if not repo.local():
6 return
7
8 class kwrepo(repo.__class__):
9 def file(self, f):
10 if f[0] == '/':
11 f = f[1:]
12 return filelog.filelog(self.sopener, f, self, self.revlogversion)
13
14 class kwfilelog(filelog.filelog):
15 def __init__(self, opener, path, repo,
16 defversion=revlog.REVLOG_DEFAULT_VERSION):
17 super(kwfilelog, self).__init__(opener, path, defversion)
18 self._repo = repo
19 self._path = path
20 def read(self, node):
21 data = super(kwfilelog, self).read(node)
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,
25 filelog=self)
26 def author(): return "$Author %s $" % c.user()
27 def date(): return "$Date %s $" % util.datestr(c.date())
28
29 data = re.sub(r'\$Author\$', author(), data)
30 data = re.sub(r'\$Date\$', date(), data)
31 return data
32 def add(self, text, meta, tr, link, p1=None, p2=None):
33 if (not util.binary(text) and
34 self._repo.ui.config("keywords", "remove", True)):
35 text = re.sub(r'\$Author[^\$]*\$', '$Author$', text)
36 text = re.sub(r'\$Date[^\$]*\$', '$Date$', text)
37 return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
38
39 filelog.filelog = kwfilelog
40 repo.__class__ = kwrepo
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.
