templatekw: allow accessing to nested namespace item by its template name
authorYuya Nishihara <yuya@tcha.org>
Sat, 30 Sep 2017 08:57:50 +0100
changeset 34541 0a0a72c043ac
parent 34540 1c7c4445686f
child 34542 153e4e05e9b3
templatekw: allow accessing to nested namespace item by its template name Since we have the dot operator, it makes more sense to write {namespaces.tags % "{tag}"} instead of {namespaces.tags % "{name}"}
mercurial/templatekw.py
tests/test-command-template.t
--- a/mercurial/templatekw.py	Sat Sep 30 08:50:24 2017 +0100
+++ b/mercurial/templatekw.py	Sat Sep 30 08:57:50 2017 +0100
@@ -618,9 +618,14 @@
     repo = ctx.repo()
 
     namespaces = util.sortdict()
+    def makensmapfn(ns):
+        # 'name' for iterating over namespaces, templatename for local reference
+        return lambda v: {'name': v, ns.templatename: v}
 
     for k, ns in repo.names.iteritems():
-        namespaces[k] = showlist('name', ns.names(repo, ctx.node()), args)
+        names = ns.names(repo, ctx.node())
+        f = _showlist('name', names, args)
+        namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity)
 
     f = _showlist('namespace', list(namespaces), args)
 
--- a/tests/test-command-template.t	Sat Sep 30 08:50:24 2017 +0100
+++ b/tests/test-command-template.t	Sat Sep 30 08:57:50 2017 +0100
@@ -4130,6 +4130,9 @@
   $ hg log -r2 -T '{get(namespaces, "bookmarks") % "{name}\n"}'
   bar
   foo
+  $ hg log -r2 -T '{namespaces.bookmarks % "{bookmark}\n"}'
+  bar
+  foo
 
 Test stringify on sub expressions