Implement tree() revision set selector
authorGregory Szorc <gps@mozilla.com>
Thu, 07 Nov 2013 17:07:06 -0800
changeset 58 e38832cd9dee8b1c070574080934b9c5cacb1072
parent 57 6529ee22dd53512f22ea84acf6a6e7ebe81b0669
child 59 3aa34de26b6f5e1d9b9e2560c8c80b5106a2a81b
push id39
push usergszorc@mozilla.com
push dateFri, 08 Nov 2013 01:07:21 +0000
Implement tree() revision set selector
__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -111,17 +111,26 @@ introduced into the repository. You can 
 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)``.
+   Retreive changesets that reference a specific bug. e.g. ``bug(784841)``.
+
+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)``.
 
 Config Options
 ==============
 
 This extension consults the following config options.
 
 mozext.headless
    Indicates that this extension is running in *headless* mode. *headless*
@@ -612,32 +621,54 @@ def revset_bug(repo, subset, x):
     n = revset.getstring(x, err)
 
     try:
         n = int(n)
     except Exception:
         raise ParseError(err)
 
     nodes = repo.changetracker.changesets_with_bug(n)
-    revs = [repo[node].rev() for node in nodes]
+    revs = set(repo[node].rev() for node in nodes)
+
+    return [r for r in subset if r in revs]
+
+
+def revset_tree(repo, subset, x):
+    """``tree(X)``
+    Changesets currently in the specified Mozilla tree.
 
-    return [r for r in revs if r in subset]
+    A tree is the name of a repository. e.g. ``central``.
+    """
+    err = _('tree() requires a string argument.')
+    tree = revset.getstring(x, err)
+
+    tree, uri = resolve_trees_to_uris([tree])[0]
+    if not uri:
+        raise util.Abort(_("Don't know about tree: %s") % tree)
+
+    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 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
+    revset.symbols['tree'] = revset_tree
 
 
 def reposetup(ui, repo):
     """Custom repository implementation.
 
     Our custom repository class tracks remote tree references so users can
     reference specific revisions on remotes.
     """