annotate hgext/interhg.py @ 8909:7bed4ad7b58f

interhg: remove unnecessary escaping
author Martin Geisler <mg@lazybytes.net>
date Fri, 19 Jun 2009 10:24:34 +0200
parents 67ee7587abea
children 0c610f77ae1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
1 # interhg.py - interhg
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
2 #
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
3 # Copyright 2007 OHASHI Hideya <ohachige@gmail.com>
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
4 #
5288
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
5 # Contributor(s):
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
6 # Edward Lee <edward.lee@engineering.uiuc.edu>
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
7 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 7216
diff changeset
8 # This software may be used and distributed according to the terms of the
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 7216
diff changeset
9 # GNU General Public License version 2, incorporated herein by reference.
8824
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
10
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
11 '''expand expressions into changelog and summaries
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
12
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
13 This extension allows the use of a special syntax in summaries,
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
14 which will be automatically expanded into links or any other
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
15 arbitrary expression, much like InterWiki does.
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
16
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
17 To enable this extension, add the following lines to your hgrc:
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
18
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
19 [extensions]
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
20 interhg =
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
21
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
22 A few example patterns (link to bug tracking, etc.):
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
23
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
24 [interhg]
8909
7bed4ad7b58f interhg: remove unnecessary escaping
Martin Geisler <mg@lazybytes.net>
parents: 8824
diff changeset
25 issues = s!issue(\d+)!<a href="http://bts/issue\1">issue\1</a>!
8824
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
26 bugzilla = s!((?:bug|b=|(?=#?\d{4,}))(?:\s*#?)(\d+))!<a..=\2">\1</a>!i
8909
7bed4ad7b58f interhg: remove unnecessary escaping
Martin Geisler <mg@lazybytes.net>
parents: 8824
diff changeset
27 boldify = s!(^|\s)#(\d+)\b! <b>#\2</b>!
8824
67ee7587abea interhg: upgrade comments to online help and improve them
Cédric Duval <cedricduval@free.fr>
parents: 8225
diff changeset
28 '''
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
29
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
30 import re
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
31 from mercurial.hgweb import hgweb_mod
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6962
diff changeset
32 from mercurial import templatefilters, extensions
6962
2af657eafeba i18n: mark strings for translation in interhg extension
Martin Geisler <mg@daimi.au.dk>
parents: 5976
diff changeset
33 from mercurial.i18n import _
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
34
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5288
diff changeset
35 orig_escape = templatefilters.filters["escape"]
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
36
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
37 interhg_table = []
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
38
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
39 def interhg_escape(x):
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
40 escstr = orig_escape(x)
5288
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
41 for regexp, format in interhg_table:
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
42 escstr = regexp.sub(format, escstr)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
43 return escstr
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
44
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5288
diff changeset
45 templatefilters.filters["escape"] = interhg_escape
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
46
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6962
diff changeset
47 def interhg_refresh(orig, self):
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
48 interhg_table[:] = []
5288
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
49 for key, pattern in self.repo.ui.configitems('interhg'):
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
50 # grab the delimiter from the character after the "s"
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
51 unesc = pattern[1]
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
52 delim = re.escape(unesc)
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
53
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
54 # identify portions of the pattern, taking care to avoid escaped
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
55 # delimiters. the replace format and flags are optional, but delimiters
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
56 # are required.
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
57 match = re.match(r'^s%s(.+)(?:(?<=\\\\)|(?<!\\))%s(.*)%s([ilmsux])*$'
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
58 % (delim, delim, delim), pattern)
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
59 if not match:
6962
2af657eafeba i18n: mark strings for translation in interhg extension
Martin Geisler <mg@daimi.au.dk>
parents: 5976
diff changeset
60 self.repo.ui.warn(_("interhg: invalid pattern for %s: %s\n")
5288
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
61 % (key, pattern))
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
62 continue
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
63
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
64 # we need to unescape the delimiter for regexp and format
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
65 delim_re = re.compile(r'(?<!\\)\\%s' % delim)
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
66 regexp = delim_re.sub(unesc, match.group(1))
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
67 format = delim_re.sub(unesc, match.group(2))
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
68
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
69 # the pattern allows for 6 regexp flags, so set them if necessary
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
70 flagin = match.group(3)
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
71 flags = 0
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
72 if flagin:
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
73 for flag in flagin.upper():
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
74 flags |= re.__dict__[flag]
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
75
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
76 try:
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
77 regexp = re.compile(regexp, flags)
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
78 interhg_table.append((regexp, format))
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
79 except re.error:
6962
2af657eafeba i18n: mark strings for translation in interhg extension
Martin Geisler <mg@daimi.au.dk>
parents: 5976
diff changeset
80 self.repo.ui.warn(_("interhg: invalid regexp for %s: %s\n")
5288
18091102a633 interhg: allow more flexible pattern specification (fixes 2/3 of issue699)
Edward Lee <edward.lee@engineering.uiuc.edu>
parents: 4817
diff changeset
81 % (key, regexp))
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6962
diff changeset
82 return orig(self)
4817
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
83
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6962
diff changeset
84 extensions.wrapfunction(hgweb_mod.hgweb, 'refresh', interhg_refresh)