namespaces: add revset for 'named(namespace)'
authorSean Farley <sean.michael.farley@gmail.com>
Tue, 13 Jan 2015 15:07:08 -0800
changeset 23836 3fb61fcbc4e4
parent 23835 aa4a1672583e
child 23837 2b79d124a12f
namespaces: add revset for 'named(namespace)' This patch adds functionality for listing all changesets in a given namespace via the revset language.
mercurial/revset.py
--- a/mercurial/revset.py	Fri Jan 09 10:52:14 2015 -0800
+++ b/mercurial/revset.py	Tue Jan 13 15:07:08 2015 -0800
@@ -1177,6 +1177,42 @@
     pat = getstring(x, _("modifies requires a pattern"))
     return checkstatus(repo, subset, pat, 0)
 
+def named(repo, subset, x):
+    """``named(namespace)``
+    The changesets in a given namespace.
+
+    If `namespace` starts with `re:`, the remainder of the string is treated as
+    a regular expression. To match a namespace that actually starts with `re:`,
+    use the prefix `literal:`.
+    """
+    # i18n: "named" is a keyword
+    args = getargs(x, 1, 1, _('named requires a namespace argument'))
+
+    ns = getstring(args[0],
+                   # i18n: "named" is a keyword
+                   _('the argument to named must be a string'))
+    kind, pattern, matcher = _stringmatcher(ns)
+    namespaces = set()
+    if kind == 'literal':
+        if pattern not in repo.names:
+            raise util.Abort(_("namespace '%s' does not exist") % ns)
+        namespaces.add(repo.names[pattern])
+    else:
+        for name, ns in repo.names.iteritems():
+            if matcher(name):
+                namespaces.add(ns)
+        if not namespaces:
+            raise util.Abort(_("no namespace exists that match '%s'")
+                             % pattern)
+
+    names = set()
+    for ns in namespaces:
+        for name in ns.listnames(repo):
+            names.update(ns.nodes(repo, name))
+
+    names -= set([node.nullrev])
+    return subset & names
+
 def node_(repo, subset, x):
     """``id(string)``
     Revision non-ambiguously specified by the given hex string prefix.
@@ -1817,6 +1853,7 @@
     "merge": merge,
     "min": minrev,
     "modifies": modifies,
+    "named": named,
     "obsolete": obsolete,
     "only": only,
     "origin": origin,