templatekw: make experimental {peerpaths} return a single-level dict (BC)
authorYuya Nishihara <yuya@tcha.org>
Mon, 18 Sep 2017 23:31:01 +0900
changeset 34538 ac38e889b33a
parent 34537 8c3dd5e462cc
child 34539 f30e59703d98
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."
mercurial/templatekw.py
tests/test-paths.t
--- a/mercurial/templatekw.py	Mon Sep 18 23:49:05 2017 +0900
+++ b/mercurial/templatekw.py	Mon Sep 18 23:31:01 2017 +0900
@@ -658,19 +658,14 @@
     """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):
--- a/tests/test-paths.t	Mon Sep 18 23:49:05 2017 +0900
+++ b/tests/test-paths.t	Mon Sep 18 23:31:01 2017 +0900
@@ -93,34 +93,25 @@
   $ 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: