bug() revision set selector
authorGregory Szorc <gps@mozilla.com>
Thu, 07 Nov 2013 16:26:04 -0800
changeset 55 125edeefc88c14c8da54fd7fd3948825a0002bc7
parent 54 825f8368425de6b04fd30f7875168f0fe4bdc19e
child 56 c3a579779e8842e53a281290070c0ba4f0e45445
push id37
push usergszorc@mozilla.com
push dateFri, 08 Nov 2013 00:27:37 +0000
bug() revision set selector
__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -105,16 +105,24 @@ information for a specific changeset.
 
 Bug Info
 ========
 
 Information about bugs is extracted from commit messages as changesets are
 introduced into the repository. You can look up information about specific
 bugs via `hg buginfo`.
 
+Revisions Sets
+==============
+
+This extension adds the following revision set selectors functions.
+
+bug(BUG)
+   Query changesets that reference a specific bug. e.g. ``bug(784841)``.
+
 Config Options
 ==============
 
 This extension consults the following config options.
 
 mozext.headless
    Indicates that this extension is running in *headless* mode. *headless*
    mode is intended for server operation, not local development.
@@ -154,21 +162,24 @@ import datetime
 import errno
 import os
 import re
 import shutil
 import sys
 
 from operator import methodcaller
 
+from mercurial import revset
+
 from mercurial.i18n import _
 from mercurial.commands import (
     push,
 )
 from mercurial.error import (
+    ParseError,
     RepoError,
 )
 from mercurial.localrepo import (
     repofilecache,
 )
 from mercurial.node import (
     hex,
 )
@@ -515,17 +526,17 @@ def buginfo(ui, repo, *bugs, **opts):
     if opts['sync']:
         repo.sync_bug_database()
         return
 
     if opts['reset']:
         repo.reset_bug_database()
         return
 
-    tracker = ChangeTracker(repo.join('changetracker.db'))
+    tracker = repo.changetracker
 
     nodes = set()
     for bug in bugs:
         nodes |= set(tracker.changesets_with_bug(bug))
 
     # Sorting by topological order would probably be preferred. This is quick
     # and easy.
     contexts = sorted([repo[node] for node in nodes], key=methodcaller('rev'))
@@ -591,26 +602,42 @@ class remoterefs(dict):
 
     def write(self):
         f = self._repo.vfs('remoterefs', 'w', atomictemp=True)
         for ref in sorted(self):
             f.write('%s %s\n' % (hex(self[ref]), encoding.fromlocal(ref)))
         f.close()
 
 
+def revset_bug(repo, subset, x):
+    """``bug(N)```
+    Changesets referencing a specified Bugzilla bug. e.g. bug(123456).
+    """
+    err = _('bug() requires an integer argument.')
+    n = revset.getstring(x, err)
+
+    try:
+        n = int(n)
+    except Exception:
+        raise ParseError(err)
+
+    return repo.changetracker.changesets_with_bug(n)
+
 def extsetup(ui):
     global bz_available
     try:
         extensions.find('bzexport')
         bz_available = True
     except KeyError:
         pass
 
     extensions.wrapcommand(commands.table, 'pull', pullexpand)
 
+    revset.symbols['bug'] = revset_bug
+
 
 def reposetup(ui, repo):
     """Custom repository implementation.
 
     Our custom repository class tracks remote tree references so users can
     reference specific revisions on remotes.
     """