diff mercurial/namespaces.py @ 33060:46fa46608ca5

namespaces: record and expose whether namespace is built-in Currently, the templating layer tends to treat each namespace as a one-off, with explicit usage of {bookmarks}, {tags}, {branch}, etc instead of using {namespaces}. It would be really useful if we could iterate over namespaces and operate on them generically. However, some consumers may wish to differentiate namespaces by whether they are built-in to core Mercurial or provided by extensions. Expected use cases include ignoring non-built-in namespaces or emitting a generic label for non-built-in namespaces. This commit introduces an attribute on namespace instances that says whether the namespace is "built-in" and then exposes this to the templating layer. As part of this, we implement a reusable extension for defining custom names on each changeset for testing. A second consumer will be introduced in a subsequent commit.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 24 Jun 2017 14:52:15 -0700
parents b98199a5c3e1
children c7b45db8f317
line wrap: on
line diff
--- a/mercurial/namespaces.py	Sat Jun 24 13:39:20 2017 -0700
+++ b/mercurial/namespaces.py	Sat Jun 24 14:52:15 2017 -0700
@@ -35,7 +35,8 @@
                       # i18n: column positioning for "hg log"
                       logfmt=_("bookmark:    %s\n"),
                       listnames=bmknames,
-                      namemap=bmknamemap, nodemap=bmknodemap)
+                      namemap=bmknamemap, nodemap=bmknodemap,
+                      builtin=True)
         self.addnamespace(n)
 
         tagnames = lambda repo: [t for t, n in repo.tagslist()]
@@ -46,7 +47,8 @@
                       logfmt=_("tag:         %s\n"),
                       listnames=tagnames,
                       namemap=tagnamemap, nodemap=tagnodemap,
-                      deprecated={'tip'})
+                      deprecated={'tip'},
+                      builtin=True)
         self.addnamespace(n)
 
         bnames = lambda repo: repo.branchmap().keys()
@@ -56,7 +58,8 @@
                       # i18n: column positioning for "hg log"
                       logfmt=_("branch:      %s\n"),
                       listnames=bnames,
-                      namemap=bnamemap, nodemap=bnodemap)
+                      namemap=bnamemap, nodemap=bnodemap,
+                      builtin=True)
         self.addnamespace(n)
 
     def __getitem__(self, namespace):
@@ -134,12 +137,13 @@
       'namemap': function that takes a name and returns a list of nodes
       'nodemap': function that takes a node and returns a list of names
       'deprecated': set of names to be masked for ordinary use
-
+      'builtin': bool indicating if this namespace is supported by core
+                 Mercurial.
     """
 
     def __init__(self, name, templatename=None, logname=None, colorname=None,
                  logfmt=None, listnames=None, namemap=None, nodemap=None,
-                 deprecated=None):
+                 deprecated=None, builtin=False):
         """create a namespace
 
         name: the namespace to be registered (in plural form)
@@ -154,7 +158,7 @@
         namemap: function that inputs a name, output node(s)
         nodemap: function that inputs a node, output name(s)
         deprecated: set of names to be masked for ordinary use
-
+        builtin: whether namespace is implemented by core Mercurial
         """
         self.name = name
         self.templatename = templatename
@@ -183,6 +187,8 @@
         else:
             self.deprecated = deprecated
 
+        self.builtin = builtin
+
     def names(self, repo, node):
         """method that returns a (sorted) list of names in a namespace that
         match a given node"""