[PATCH] namespaces: add revset for 'named(namespace)'

Sean Farley sean.michael.farley at gmail.com
Tue Jan 13 23:07:48 UTC 2015


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1421190428 28800
#      Tue Jan 13 15:07:08 2015 -0800
# Node ID 4567f50220d68dbd6e5bb6e7f133686b714cc705
# Parent  678f53865c6860a950392691814766957ee89316
namespaces: add revset for 'named(namespace)'

This patch adds functionality for listing all changesets in a given namespace
via the revset language.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1175,10 +1175,46 @@ def modifies(repo, subset, x):
     """
     # i18n: "modifies" is a keyword
     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.
     """
     # i18n: "id" is a keyword
@@ -1815,10 +1851,11 @@ symbols = {
     "_matchfiles": _matchfiles,
     "max": maxrev,
     "merge": merge,
     "min": minrev,
     "modifies": modifies,
+    "named": named,
     "obsolete": obsolete,
     "only": only,
     "origin": origin,
     "outgoing": outgoing,
     "p1": p1,


More information about the Mercurial-devel mailing list