# interhg.py - interhg # # Copyright 2007 OHASHI Hideya # # Contributor(s): # Edward Lee # # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. # # The `interhg' Mercurial extension allows you to change changelog and # summary text just like InterWiki way. # # To enable this extension: # # [extensions] # interhg = # # These are some example patterns (link to bug tracking, etc.) # # [interhg] # issues = s!issue(\d+)!issue\1<\/a>! # bugzilla = s!((?:bug|b=|(?=#?\d{4,}))(?:\s*#?)(\d+))!\1!i # boldify = s/(^|\s)#(\d+)\b/ #\2<\/b>/ # # Add any number of names and patterns to match import re from mercurial.hgweb import hgweb_mod from mercurial import templatefilters from mercurial.i18n import _ orig_escape = templatefilters.filters["escape"] interhg_table = [] def interhg_escape(x): escstr = orig_escape(x) for regexp, format in interhg_table: escstr = regexp.sub(format, escstr) return escstr templatefilters.filters["escape"] = interhg_escape orig_refresh = hgweb_mod.hgweb.refresh def interhg_refresh(self): interhg_table[:] = [] for key, pattern in self.repo.ui.configitems('interhg'): # grab the delimiter from the character after the "s" unesc = pattern[1] delim = re.escape(unesc) # identify portions of the pattern, taking care to avoid escaped # delimiters. the replace format and flags are optional, but delimiters # are required. match = re.match(r'^s%s(.+)(?:(?<=\\\\)|(?