Mon Dec 25 22:18:20 UTC 2006 Alberto Bertogli <albertito@gmail.com>
* Add support for regexp-based replacing.
Add an option to replace text in the summary, using regexps. This allows you
to configure darcsweb to automatically detect and put links to other commits
or bug numbers.
This patch is heavily based on the one written by Kirill Smelkov
(kirr@mns.spb.ru).
{
hunk ./config.py.sample 57
+
+ # If you want darcsweb to automatically detect embedded URLs,
+ # define them here, using python-style regexps like the examples
+ # below. They will be replaced in summaries, logs, and commits.
+ # The following variables are replaced:
+ # myreponame: repository link (darcsweb.cgi?r=repo)
+ # reponame: repository name (repo)
+ #
+ #url_links = (
+ # Format is: (regexp, replacement)
+ # Some examples:
+ #
+ # Detect '#NNN' as a reference to bug database
+ #(r'#([0-9]+)',
+ # r'<a href="/bugs/show_bug.cgi?id=\1">#\1</a>'),
+ #
+ # Replace hashes with commit-links.
+ #(r'(\d{14}-[0-9a-f]{5}-[0-9a-f]{40}\.gz)',
+ # r'<a href="%(myreponame)s;a=commit;h=\1">\1</a>'),
+ #)
hunk ./darcsweb.cgi 164
+def replace_links(s):
+ """Replace user defined strings with links, as specified in the
+ configuration file."""
+ import re
+
+ vardict = {
+ "myreponame": config.myreponame,
+ "reponame": config.reponame,
+ }
+
+ for link_pat, link_dst in config.url_links:
+ s = re.sub(link_pat, link_dst % vardict, s)
+
+ return s
+
+
hunk ./darcsweb.cgi 1165
- comment = escape(p.comment)
+ comment = replace_links(escape(p.comment))
hunk ./darcsweb.cgi 1608
- comment = escape(p.comment)
+ comment = replace_links(escape(p.comment))
hunk ./darcsweb.cgi 1611
- print escape(p.name), '<br/><br/>'
+ print replace_links(escape(p.name)), '<br/><br/>'
hunk ./darcsweb.cgi 2340
+ if "url_links" in dir(base):
+ config.url_links = base.url_links
+ else:
+ config.url_links = ()
+
}