Patchwork [5,of,8] templatekw: make experimental {peerpaths} return a single-level dict (BC)

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

Comments

Yuya Nishihara - Oct. 6, 2017, 4:05 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1505745061 -32400
#      Mon Sep 18 23:31:01 2017 +0900
# Node ID 9810c09653f2e980929539ed2a8d76478dc98ad1
# Parent  3a85ee1cfabde421202ea11c482c15bc0c986e5d
templatekw: make experimental {peerpaths} return a single-level dict (BC)

This was planned as in c0d8de2724ce, "{peerpaths.default.pushurl} will be
translated to peerpaths['default'].makemap()['pushurl'], which means
{peerpaths} should be a single-level dict and sub-options should be
makemap()-ed."

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -658,19 +658,14 @@  def showpeerpaths(repo, **args):
     """A dictionary of repository locations defined in the [paths] section
     of your configuration file. (EXPERIMENTAL)"""
     # see commands.paths() for naming of dictionary keys
-    paths = util.sortdict()
-    for k, p in sorted(repo.ui.paths.iteritems()):
-        d = util.sortdict()
-        d['url'] = p.rawloc
+    paths = repo.ui.paths
+    urls = util.sortdict((k, p.rawloc) for k, p in sorted(paths.iteritems()))
+    def makemap(k):
+        p = paths[k]
+        d = {'name': k, 'url': p.rawloc}
         d.update((o, v) for o, v in sorted(p.suboptions.iteritems()))
-        def f(d):
-            yield d['url']
-        paths[k] = hybriddict(d, gen=f(d))
-
-    # no hybriddict() since d['path'] can't be formatted as a string. perhaps
-    # hybriddict() should call templatefilters.stringify(d[value]).
-    return _hybrid(None, paths, lambda k: {'name': k, 'path': paths[k]},
-                   lambda k: '%s=%s' % (k, paths[k]['url']))
+        return d
+    return _hybrid(None, urls, makemap, lambda k: '%s=%s' % (k, urls[k]))
 
 @templatekeyword("predecessors")
 def showpredecessors(repo, ctx, **args):
diff --git a/tests/test-paths.t b/tests/test-paths.t
--- a/tests/test-paths.t
+++ b/tests/test-paths.t
@@ -93,34 +93,25 @@  log template:
   $ hg log -rnull -T '{join(peerpaths, "\n")}\n'
   dupe=$TESTTMP/b#tip (glob)
   expand=$TESTTMP/a/$SOMETHING/bar (glob)
-  $ hg log -rnull -T '{peerpaths % "{name}: {path}\n"}'
+  $ hg log -rnull -T '{peerpaths % "{name}: {url}\n"}'
   dupe: $TESTTMP/b#tip (glob)
   expand: $TESTTMP/a/$SOMETHING/bar (glob)
   $ hg log -rnull -T '{get(peerpaths, "dupe")}\n'
   $TESTTMP/b#tip (glob)
 
- (but a path is actually a dict of url and sub-options)
+ (sub options can be populated by map/dot operation)
 
-  $ hg log -rnull -T '{join(get(peerpaths, "dupe"), "\n")}\n'
-  url=$TESTTMP/b#tip (glob)
-  pushurl=https://example.com/dupe
-  $ hg log -rnull -T '{get(peerpaths, "dupe") % "{key}: {value}\n"}'
+  $ hg log -rnull \
+  > -T '{get(peerpaths, "dupe") % "url: {url}\npushurl: {pushurl}\n"}'
   url: $TESTTMP/b#tip (glob)
   pushurl: https://example.com/dupe
-  $ hg log -rnull -T '{get(get(peerpaths, "dupe"), "pushurl")}\n'
+  $ hg log -rnull -T '{peerpaths.dupe.pushurl}\n'
   https://example.com/dupe
 
- (so there's weird behavior)
-
-  $ hg log -rnull -T '{get(peerpaths, "dupe")|count}\n'
-  2
-  $ hg log -rnull -T '{get(peerpaths, "dupe")|stringify|count}\n'
-  [0-9]{2,} (re)
-
- (in JSON, it's a dict of dicts)
+ (in JSON, it's a dict of urls)
 
   $ hg log -rnull -T '{peerpaths|json}\n' | sed 's|\\\\|/|g'
-  {"dupe": {"pushurl": "https://example.com/dupe", "url": "$TESTTMP/b#tip"}, "expand": {"url": "$TESTTMP/a/$SOMETHING/bar"}}
+  {"dupe": "$TESTTMP/b#tip", "expand": "$TESTTMP/a/$SOMETHING/bar"}
 
 password should be masked in plain output, but not in machine-readable/template
 output: