debugformat: embed raw values in JSON and template output
authorYuya Nishihara <yuya@tcha.org>
Sun, 10 Dec 2017 19:41:49 +0900
changeset 35378 9144e898cad5
parent 35377 c0b6fa74e007
child 35379 6c28956ba2d4
debugformat: embed raw values in JSON and template output
mercurial/debugcommands.py
tests/test-upgrade-repo.t
--- a/mercurial/debugcommands.py	Sun Dec 10 19:39:39 2017 +0900
+++ b/mercurial/debugcommands.py	Sun Dec 10 19:41:49 2017 +0900
@@ -873,15 +873,18 @@
     def makeformatname(name):
         return '%s:' + (' ' * (maxvariantlength - len(name)))
 
-    def formatvalue(value):
-        if util.safehasattr(value, 'startswith'):
-            return value
-        if value:
-            return 'yes'
-        else:
-            return 'no'
+    fm = ui.formatter('debugformat', opts)
+    if fm.isplain():
+        def formatvalue(value):
+            if util.safehasattr(value, 'startswith'):
+                return value
+            if value:
+                return 'yes'
+            else:
+                return 'no'
+    else:
+        formatvalue = pycompat.identity
 
-    fm = ui.formatter('debugformat', opts)
     fm.plain('format-variant')
     fm.plain(' ' * (maxvariantlength - len('format-variant')))
     fm.plain(' repo')
--- a/tests/test-upgrade-repo.t	Sun Dec 10 19:39:39 2017 +0900
+++ b/tests/test-upgrade-repo.t	Sun Dec 10 19:41:49 2017 +0900
@@ -85,28 +85,28 @@
   $ hg debugformat -Tjson
   [
    {
-    "config": "yes",
-    "default": "yes",
+    "config": true,
+    "default": true,
     "name": "fncache",
-    "repo": "yes"
+    "repo": true
    },
    {
-    "config": "yes",
-    "default": "yes",
+    "config": true,
+    "default": true,
     "name": "dotencode",
-    "repo": "yes"
+    "repo": true
    },
    {
-    "config": "yes",
-    "default": "yes",
+    "config": true,
+    "default": true,
     "name": "generaldelta",
-    "repo": "yes"
+    "repo": true
    },
    {
-    "config": "yes",
-    "default": "yes",
+    "config": true,
+    "default": true,
     "name": "plain-cl-delta",
-    "repo": "yes"
+    "repo": true
    },
    {
     "config": "zlib",