Add templates for {bug} and {bugs}
authorGregory Szorc <>
Thu, 07 Nov 2013 18:18:02 -0800
changeset 60 46147591a90abc69edffb2d67a1d192df48bcb93
parent 59 3aa34de26b6f5e1d9b9e2560c8c80b5106a2a81b
child 61 0acb68c2180069f70c4f98faa0fd7bd9023ffaf9
push id41
push dateFri, 08 Nov 2013 02:18:20 +0000
Add templates for {bug} and {bugs}
--- a/
+++ b/
@@ -129,16 +129,27 @@ tree(TREE)
    Retrieve changesets that are currently in the specified tree.
    Trees are specified with a known alias. e.g. ``tree(central)``.
    It's possible to see which changesets are in some tree but not others.
    e.g. to find changesets in *inbound* that haven't merged to *central*
    yet, do ``tree(inbound) - tree(central)``.
+This extension provides keywords that can used with templates.
+   The bug primarily associated with a changeset.
+   All the bugs associated with a changeset.
 Config Options
 This extension consults the following config options.
    Indicates that this extension is running in *headless* mode. *headless*
    mode is intended for server operation, not local development.
@@ -177,17 +188,20 @@ mozext.refs_as_bookmarks
 import datetime
 import errno
 import os
 import shutil
 import sys
 from operator import methodcaller
-from mercurial import revset
+from mercurial import (
+    revset,
+    templatekw,
 from mercurial.i18n import _
 from mercurial.commands import (
 from mercurial.error import (
@@ -676,30 +690,44 @@ def revset_tree(repo, subset, x):
     ref = '%s/default' % tree
     head = repo[ref].rev()
     ancestors = set(repo.changelog.ancestors([head], inclusive=True))
     return [r for r in subset if r in ancestors]
+def template_bug(repo, ctx, templ, **args):
+    """:bug: String. The bug this changeset is most associated with."""
+    bugs = parse_bugs(ctx.description())
+    return bugs[0] if bugs else None
+def template_bugs(repo, ctx, templ, **args):
+    """:bugs: List of ints. The bugs associated with this changeset."""
+    return parse_bugs(ctx.description())
 def extsetup(ui):
     global bz_available
         bz_available = True
     except KeyError:
     extensions.wrapcommand(commands.table, 'pull', pullexpand)
     revset.symbols['bug'] = revset_bug
     revset.symbols['me'] = revset_me
     revset.symbols['tree'] = revset_tree
+    templatekw.keywords['bug'] = template_bug
+    templatekw.keywords['bugs'] = template_bugs
 def reposetup(ui, repo):
     """Custom repository implementation.
     Our custom repository class tracks remote tree references so users can
     reference specific revisions on remotes.