Patchwork [1,of,4] namespaces: add 'listnames' property

mail settings
Submitter Sean Farley
Date Jan. 7, 2015, 10:02 p.m.
Message ID <f1bede576d4a0369e2cd.1420668132@laptop.local>
Download mbox | patch
Permalink /patch/7362/
State Accepted
Commit 50229b4c33bec82f6ba972caeb08e89205ce2ceb
Headers show


Sean Farley - Jan. 7, 2015, 10:02 p.m.
# HG changeset patch
# User Sean Farley <>
# Date 1418681340 28800
#      Mon Dec 15 14:09:00 2014 -0800
# Node ID f1bede576d4a0369e2cd5245cde1ee2c96ee5ee5
# Parent  f82173a90c2c9d0d32216fe7243ec51fc6d44ff7
namespaces: add 'listnames' property

Currently, we have no way to list all the names in a given namespace. This is
needed for things such as tab completion. Future patches will use this patch
for exactly that purpose.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -26,20 +26,23 @@  class namespaces(object):
         ns = namespace
         # we need current mercurial named objects (bookmarks, tags, and
         # branches) to be initialized somewhere, so that place is here
         n = ns("bookmarks", "bookmark",
+               lambda repo: repo._bookmarks.keys(),
                lambda repo, name: tolist(repo._bookmarks.get(name)),
                lambda repo, name: repo.nodebookmarks(name))
         n = ns("tags", "tag",
+               lambda repo: [t for t, n in repo.tagslist()],
                lambda repo, name: tolist(repo._tagscache.tags.get(name)),
                lambda repo, name: repo.nodetags(name))
         n = ns("branches", "branch",
+               lambda repo: repo.branchmap().keys(),
                lambda repo, name: tolist(repo.branchtip(name)),
                lambda repo, node: [repo[node].branch()])
     def __getitem__(self, namespace):
@@ -102,26 +105,30 @@  class namespace(object):
     This namespace object will define the properties we need:
       'name': the namespace (plural form)
       'templatename': name to use for templating (usually the singular form
                       of the plural namespace name)
+      'listnames': list of all names in the namespace (usually the keys of a
+                   dictionary)
       'namemap': function that takes a name and returns a list of nodes
       'nodemap': function that takes a node and returns a list of names
-    def __init__(self, name, templatename, namemap, nodemap):
+    def __init__(self, name, templatename, listnames, namemap, nodemap):
         """create a namespace
         name: the namespace to be registered (in plural form)
+        listnames: function to list all names
         templatename: the name to use for templating
         namemap: function that inputs a node, output name(s)
         nodemap: function that inputs a name, output node(s)
         """ = name
         self.templatename = templatename
+        self.listnames = listnames
         self.namemap = namemap
         self.nodemap = nodemap
     def names(self, repo, node):
         """method that returns a (sorted) list of names in a namespace that