[PATCH] interhg: extension for hyperlink to BTS in changeset and changelog

OHASHI Hideya ohachige at gmail.com
Sun Jun 17 10:59:42 CDT 2007


# HG changeset patch
# User OHASHI Hideya <ohachige at gmail.com>
# Date 1182095829 -32400
# Node ID de6a2b8490c26f156bec34c81e4fbcf13cb536ba
# Parent  3daed3680554787f32bdc4cac7c034ad6129692d
interhg: extension for hyperlink to BTS in changeset and changelog.

When commit log has some BTS IDs, Hyperlink will be shown up.
The BTS ID format is configurable.

diff -r 3daed3680554 -r de6a2b8490c2 doc/hgrc.5.txt
--- a/doc/hgrc.5.txt	Wed Jun 13 13:15:53 2007 -0500
+++ b/doc/hgrc.5.txt	Mon Jun 18 00:57:09 2007 +0900
@@ -537,6 +537,17 @@ web::
   templates;;
     Where to find the HTML templates. Default is install path.
 
+interhg::
+  Settings for extensions that links to BTS.
+  bts;;
+    Base URL to use BTS. Such as Bugzilla, trac, redMine.
+    Example: "http://www.selenic.com/mercurial/bts/issue"
+  regexp;;
+    Regular expression for BTS issue keywords. Default is #(\d+)
+    Example: "issue(\d+)"
+  format;;
+    Print format. Default is #%%s
+    Example: "issue%%s"
 
 AUTHOR
 ------
diff -r 3daed3680554 -r de6a2b8490c2 hgext/interhg.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext/interhg.py	Mon Jun 18 00:57:09 2007 +0900
@@ -0,0 +1,20 @@
+# interhg.py - interhg
+#
+# Copyright 2007 OHASHI Hideya <ohachige at gmail.com>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+import re
+from mercurial.i18n import _
+
+def tickets(self, desc):
+    tickets = []
+    regexp = self.config('interhg', 'regexp', '#(\d+)')
+    format = self.config('interhg', 'format', '#%s')
+    t_ids = re.findall(regexp, desc)
+    bts = self.config('interhg', 'bts', 'http://localhost/')
+    for t_id in t_ids:
+        t_str = format % t_id
+        tickets.append(self.t("ticketlink", node=t_str, baseurl=bts))
+    return tickets
diff -r 3daed3680554 -r de6a2b8490c2 mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Wed Jun 13 13:15:53 2007 -0500
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Jun 18 00:57:09 2007 +0900
@@ -11,7 +11,7 @@ from mercurial.node import *
 from mercurial.node import *
 from mercurial.i18n import gettext as _
 from mercurial import mdiff, ui, hg, util, archival, streamclone, patch
-from mercurial import revlog, templater
+from mercurial import revlog, templater, extensions
 from common import get_mtime, staticfile, style_map, paritygen
 
 def _up(p):
@@ -78,6 +78,11 @@ class hgweb(object):
         self.templatepath = self.config("web", "templates",
                                         templater.templatepath(),
                                         untrusted=False)
+        self.interhg = None
+        try:
+            self.interhg = extensions.find('interhg')
+        except KeyError:
+            pass
 
     # The CGI scripts are often run by a user different from the repo owner.
     # Trust the settings from the .hg/hgrc files by default.
@@ -135,6 +140,11 @@ class hgweb(object):
 
     def nodetagsdict(self, node):
         return [{"name": i} for i in self.repo.nodetags(node)]
+
+    def tickets(self, desc):
+        if self.interhg:
+            return self.interhg.tickets(self, desc)
+        return []
 
     def nodebranchdict(self, ctx):
         branches = []
@@ -219,6 +229,7 @@ class hgweb(object):
                              "changelogtag": self.showtag("changelogtag",n),
                              "desc": ctx.description(),
                              "date": ctx.date(),
+                             "tickets": self.tickets(ctx.description()),
                              "files": self.listfilediffs(ctx.files(), n),
                              "rev": i,
                              "node": hex(n),
@@ -327,6 +338,7 @@ class hgweb(object):
                      author=ctx.user(),
                      desc=ctx.description(),
                      date=ctx.date(),
+                     tickets=self.tickets(ctx.description()),
                      files=files,
                      archives=self.archivelist(hex(n)),
                      tags=self.nodetagsdict(n),
diff -r 3daed3680554 -r de6a2b8490c2 templates/changelogentry.tmpl
--- a/templates/changelogentry.tmpl	Wed Jun 13 13:15:53 2007 -0500
+++ b/templates/changelogentry.tmpl	Mon Jun 18 00:57:09 2007 +0900
@@ -1,7 +1,7 @@
 <table class="logEntry parity#parity#">
  <tr>
   <th class="age">#date|age# ago:</th>
-  <th class="firstline">#desc|strip|firstline|escape#</th>
+  <th class="firstline">#desc|strip|firstline|escape# #tickets#</th>
  </tr>
  <tr>
   <th class="revision">changeset #rev#:</th>
diff -r 3daed3680554 -r de6a2b8490c2 templates/changeset.tmpl
--- a/templates/changeset.tmpl	Wed Jun 13 13:15:53 2007 -0500
+++ b/templates/changeset.tmpl	Mon Jun 18 00:57:09 2007 +0900
@@ -34,7 +34,7 @@
  <td class="files">#files#</td></tr>
 <tr>
  <th class="description">description:</th>
- <td class="description">#desc|strip|escape|addbreaks#</td>
+ <td class="description">#desc|strip|escape|addbreaks#<br>#tickets#</td>
 </tr>
 </table>
 
diff -r 3daed3680554 -r de6a2b8490c2 templates/map
--- a/templates/map	Wed Jun 13 13:15:53 2007 -0500
+++ b/templates/map	Mon Jun 18 00:57:09 2007 +0900
@@ -54,3 +54,4 @@ error = error.tmpl
 error = error.tmpl
 urlparameter = '#separator##name#=#value|urlescape#'
 hiddenformentry = '<input type="hidden" name="#name#" value="#value|escape#" />'
+ticketlink = '<a href="#baseurl##node|short#">#node|escape#</a> '


More information about the Mercurial-devel mailing list