18 RCSFile: basename,v |
18 RCSFile: basename,v |
19 Source: /path/to/basename,v |
19 Source: /path/to/basename,v |
20 Id: basename,v csetid %Y-%m-%d %H:%M:%S %z shortname |
20 Id: basename,v csetid %Y-%m-%d %H:%M:%S %z shortname |
21 Header: /path/to/basename,v csetid %Y-%m-%d %H:%M:%S %z shortname |
21 Header: /path/to/basename,v csetid %Y-%m-%d %H:%M:%S %z shortname |
22 |
22 |
23 Install: |
|
24 Copy keyword.py in hgext folder. |
|
25 |
|
26 Simple setup in hgrc: |
23 Simple setup in hgrc: |
27 |
24 |
28 # enable extension |
25 # enable extension |
29 hgext.keyword = |
26 hgext.keyword = |
|
27 # or, if script not in hgext folder: |
|
28 # hgext.keyword = /full/path/to/script |
30 |
29 |
31 # filename patterns for expansion are configured in this section |
30 # filename patterns for expansion are configured in this section |
32 [keyword] |
31 [keyword] |
33 **.py = expand |
32 **.py = expand |
34 ... |
33 ... |
35 ''' |
34 ''' |
36 |
35 |
37 from mercurial import context, util |
36 from mercurial import context, util |
38 import os.path, re |
37 import os.path, re, sys |
39 |
38 |
40 |
39 |
41 re_kw = re.compile( |
40 re_kw = re.compile( |
42 r'\$(Id|Header|Author|Date|Revision|RCSFile|Source)[^$]*?\$') |
41 r'\$(Id|Header|Author|Date|Revision|RCSFile|Source)[^$]*?\$') |
43 |
42 |
128 text = re_kw.sub(r'$\1$', text) |
127 text = re_kw.sub(r'$\1$', text) |
129 return super(kwfilelog, self).cmp(node, text) |
128 return super(kwfilelog, self).cmp(node, text) |
130 |
129 |
131 filelog.filelog = kwfilelog |
130 filelog.filelog = kwfilelog |
132 repo.__class__ = kwrepo |
131 repo.__class__ = kwrepo |
133 ui.setconfig('hooks', |
132 # import keyword from pretxncommit hook even if it is not in hgext folder |
134 'pretxncommit.keyword', 'python:hgext.keyword.pretxnkw') |
133 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
|
134 ui.setconfig('hooks', 'pretxncommit.keyword', 'python:%s.pretxnkw' |
|
135 % os.path.splitext(os.path.basename(__file__))[0]) |
135 |
136 |
136 |
137 |
137 def pretxnkw(ui, repo, hooktype, **args): |
138 def pretxnkw(ui, repo, hooktype, **args): |
138 '''pretxncommit hook that collects candidates for keyword expansion |
139 '''pretxncommit hook that collects candidates for keyword expansion |
139 on commit and expands keywords in working dir.''' |
140 on commit and expands keywords in working dir.''' |
140 from mercurial.i18n import gettext as _ |
141 from mercurial.i18n import gettext as _ |
141 # above line for backwards compatibility; can be changed to |
142 # above line for backwards compatibility; can be changed to |
142 # from mercurial.i18n import _ |
143 # from mercurial.i18n import _ |
143 # some day |
144 # some day |
144 from mercurial import cmdutil, commands |
145 from mercurial import cmdutil, commands |
145 import sys |
|
146 |
146 |
147 if hooktype != 'pretxncommit': |
147 if hooktype != 'pretxncommit': |
148 return True |
148 return True |
149 |
149 |
150 cmd, sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[1:] |
150 cmd, sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[1:] |