17 super(kwfilelog, self).__init__(opener, path, defversion) |
19 super(kwfilelog, self).__init__(opener, path, defversion) |
18 self._repo = repo |
20 self._repo = repo |
19 self._path = path |
21 self._path = path |
20 |
22 |
21 def read(self, node): |
23 def read(self, node): |
22 def gethgkw(): |
24 data = super(kwfilelog, self).read(node) |
|
25 if not util.binary(data): |
23 c = context.filectx(self._repo, self._path, fileid=node, |
26 c = context.filectx(self._repo, self._path, fileid=node, |
24 filelog=self) |
27 filelog=self) |
25 filename = c.path() |
28 f = c.path() |
26 for pat, opt in self._repo.ui.configitems('keyword'): |
29 for pat, opt in self._repo.ui.configitems('keyword'): |
27 if opt == 'expand': |
30 if opt == 'expand': |
28 mf = util.matcher(self._repo.root, |
31 mf = util.matcher(self._repo.root, |
29 '', [pat], [], [])[1] |
32 '', [pat], [], [])[1] |
30 if mf(filename): |
33 if mf(f): |
31 return '$Hg: %s,v %s %s %s $' % ( |
34 re_kw = re.compile(r'\$(%s)\$' % hgkeywords) |
32 os.path.basename(filename), |
35 |
33 c.changectx(), |
36 def kwexpand(matchobj): |
34 util.datestr(date=c.date(), |
37 RCSFile = os.path.basename(f)+',v' |
35 format=util.defaultdateformats[0]), |
38 Source = os.path.join(self._repo.root, f)+',v' |
36 util.shortuser(c.user()) |
39 Revision = c.changectx() |
37 ) |
40 Date = util.datestr(date=c.date()) |
38 data = super(kwfilelog, self).read(node) |
41 Author = c.user() |
39 if not util.binary(data): |
42 revdateauth = '%s %s %s' % ( |
40 hgkw = gethgkw() |
43 Revision, |
41 if hgkw: |
44 util.datestr(date=c.date(), |
42 data = data.replace('$Hg$', hgkw) |
45 format=util.defaultdateformats[0]), |
|
46 util.shortuser(Author)) |
|
47 Header = '%s %s' % (Source, revdateauth) |
|
48 Id = '%s %s' % (RCSFile, revdateauth) |
|
49 return '$%s: %s $' % ( |
|
50 matchobj.group(1), eval(matchobj.group(1))) |
|
51 |
|
52 return re_kw.sub(kwexpand, data) |
43 return data |
53 return data |
44 |
54 |
45 def add(self, text, meta, tr, link, p1=None, p2=None): |
55 def add(self, text, meta, tr, link, p1=None, p2=None): |
46 if (not util.binary(text) and |
56 if (not util.binary(text) and |
47 self._repo.ui.config('keyword', 'remove', True)): |
57 self._repo.ui.config('keyword', 'remove', True)): |
48 re_kw = re.compile(r'\$Hg: [^$]+?,v [a-z0-9]{12} [^$]+? \$') |
58 re_kw = re.compile(r'\$(%s): [^$]+? \$' % hgkeywords) |
49 text = re_kw.sub('$Hg$', text) |
59 text = re_kw.sub(r'$\1$', text) |
50 return super(kwfilelog, self).add(text, meta, tr, link, p1, p2) |
60 return super(kwfilelog, self).add(text, meta, tr, link, p1, p2) |
51 |
61 |
52 filelog.filelog = kwfilelog |
62 filelog.filelog = kwfilelog |
53 repo.__class__ = kwrepo |
63 repo.__class__ = kwrepo |