File viewvc-buglink.patch of Package viewvc

--- conf/viewvc.conf.dist
+++ conf/viewvc.conf.dist
@@ -329,6 +329,21 @@
 ##---------------------------------------------------------------------------
 [options]
 
+## The 'buglink_base' value is a string that can be used to form a URL
+## by appending a bug number.  If viewvc sees something that looks
+## like a bug number in a log message (eg. "bug 12345" or "#12345"), it
+## will be displayed as a link to the bug in your bug tracking system.
+##
+## For a Bugzilla installation, you probably want to set this to
+## something like "http://hostname/show_bug.cgi?id=".  For the Debian
+## bug tracker, you might use
+## "http://hostname/cgi-bin/bugreport.cgi?bug=".
+##
+## If 'buglink_base' is not set, then bug tracker links won't be
+## generated.
+##
+#buglink_base = http://example.com/show_bug.cgi?id=
+
 ## root_as_url_component: Interpret the first path component in the URL
 ## after the script location as the root to use.  This is an
 ## alternative to using the "root=" query key. If ViewVC is configured
--- lib/config.py
+++ lib/config.py
@@ -438,6 +438,7 @@
     self.options.log_pagesize = 0
     self.options.log_pagesextra = 3
     self.options.limit_changes = 100
+    self.options.buglink_base = None
 
     self.templates.diff = None
     self.templates.directory = None
--- lib/viewvc.py
+++ lib/viewvc.py
@@ -1122,6 +1122,10 @@
     return out, out_len, 0
 
     
+# Matches bug numbers
+_re_rewrite_bug = re.compile(r'((?:\bbug[\s:#+]|[^&]#|^#)\s*(\d\d+))', re.I)
+_re_buglink_prefix = ""
+ 
 class ViewVCHtmlFormatter:
   """Format a string as HTML-encoded output with customizable markup
   rules, for example turning strings that look like URLs into anchor links.
@@ -1134,6 +1138,19 @@
   def __init__(self):
     self._formatters = []
 
+  def format_bugzilla(self, mobj, userdata, maxlen=0):
+    """Return a 2-tuple containing:
+         - the text represented by MatchObject MOBJ, formatted as
+           linkified URL, with no more than MAXLEN characters in the
+           non-HTML-tag bits.  If MAXLEN is 0, there is no maximum.
+         - the number of non-HTML-tag characters returned.
+    """
+    s = mobj.group(0)
+    trunc_s = maxlen and s[:maxlen] or s
+    return '<a href="%s%s">%s</a>' % (_re_buglink_prefix, urllib.quote(mobj.group(2)),
+                    sapi.escape(trunc_s)), \
+                    len(trunc_s)
+
   def format_url(self, mobj, userdata, maxlen=0):
     """Return a 2-tuple containing:
          - the text represented by MatchObject MOBJ, formatted as
@@ -1356,6 +1373,11 @@
           lf.add_formatter(_re_rewrite_svnrevref, lf.format_svnrevref,
                            revision_to_url)
 
+        if cfg.options.buglink_base is not None:
+          global _re_buglink_prefix
+          _re_buglink_prefix = cfg.options.buglink_base
+          lf.add_formatter(_re_rewrite_bug, lf.format_bugzilla)
+
         # Rewrite email addresses.
         if cfg.options.mangle_email_addresses == 2:
           lf.add_formatter(_re_rewrite_email, lf.format_email_truncated)
openSUSE Build Service is sponsored by