Patchwork [8,of,8] templatekw: allow accessing to nested namespace item by its template name

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 6, 2017, 4:05 p.m.
Message ID <5584116d8f7136476f2e.1507305958@mimosa>
Download mbox | patch
Permalink /patch/24609/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 6, 2017, 4:05 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1506758270 -3600
#      Sat Sep 30 08:57:50 2017 +0100
# Node ID 5584116d8f7136476f2ea835277568c372f0c866
# Parent  099e1c38ca3b261be0b89298356a1ec5ff9d32b5
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}"}
Augie Fackler - Oct. 10, 2017, 12:59 a.m.
On Sat, Oct 07, 2017 at 01:05:58AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1506758270 -3600
> #      Sat Sep 30 08:57:50 2017 +0100
> # Node ID 5584116d8f7136476f2ea835277568c372f0c866
> # Parent  099e1c38ca3b261be0b89298356a1ec5ff9d32b5
> templatekw: allow accessing to nested namespace item by its template name

queued, thanks

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -618,9 +618,14 @@  def shownamespaces(**args):
     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)
 
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -4130,6 +4130,9 @@  Test namespaces dict
   $ 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