Mercurial > hg > mercurial-crew-with-dirclash
comparison hgext/interhg.py @ 4818:0ac6b537893f
interhg extension allows you to change changelog text like InterWiki.
author | OHASHI Hideya <ohachige@gmail.com> |
---|---|
date | Tue, 03 Jul 2007 00:13:52 +0900 |
parents | |
children | 18091102a633 |
comparison
equal
deleted
inserted
replaced
4817:c10d3bc05a8d | 4818:0ac6b537893f |
---|---|
1 # interhg.py - interhg | |
2 # | |
3 # Copyright 2007 OHASHI Hideya <ohachige@gmail.com> | |
4 # | |
5 # This software may be used and distributed according to the terms | |
6 # of the GNU General Public License, incorporated herein by reference. | |
7 # | |
8 # The `interhg' Mercurial extension allows you to change changelog and | |
9 # summary text just like InterWiki way. | |
10 # | |
11 # To enable this extension: | |
12 # | |
13 # [extensions] | |
14 # interhg = | |
15 # | |
16 # This is an example to link to a bug tracking system. | |
17 # | |
18 # [interhg] | |
19 # pat1 = s/issue(\d+)/ <a href="http:\/\/bts\/issue\1">issue\1<\/a> / | |
20 # | |
21 # You can add patterns to use pat2, pat3, ... | |
22 # For exapmle. | |
23 # | |
24 # pat2 = s/(^|\s)#(\d+)\b/ <b>#\2<\/b> / | |
25 | |
26 import re | |
27 from mercurial.hgweb import hgweb_mod | |
28 from mercurial import templater | |
29 | |
30 orig_escape = templater.common_filters["escape"] | |
31 | |
32 interhg_table = [] | |
33 | |
34 def interhg_escape(x): | |
35 escstr = orig_escape(x) | |
36 for pat in interhg_table: | |
37 regexp = pat[0] | |
38 format = pat[1] | |
39 escstr = regexp.sub(format, escstr) | |
40 return escstr | |
41 | |
42 templater.common_filters["escape"] = interhg_escape | |
43 | |
44 orig_refresh = hgweb_mod.hgweb.refresh | |
45 | |
46 def interhg_refresh(self): | |
47 interhg_table[:] = [] | |
48 num = 1 | |
49 while True: | |
50 key = 'pat%d' % num | |
51 pat = self.config('interhg', key) | |
52 if pat == None: | |
53 break | |
54 pat = pat[2:-1] | |
55 span = re.search(r'[^\\]/', pat).span() | |
56 regexp = pat[:span[0] + 1] | |
57 format = pat[span[1]:] | |
58 format = re.sub(r'\\/', '/', format) | |
59 regexp = re.compile(regexp) | |
60 interhg_table.append((regexp, format)) | |
61 num += 1 | |
62 return orig_refresh(self) | |
63 | |
64 hgweb_mod.hgweb.refresh = interhg_refresh |