[PATCH 2 of 3] debugformat: embed raw values in JSON and template output

Yuya Nishihara yuya at tcha.org
Sun Dec 10 05:58:16 EST 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1512902509 -32400
#      Sun Dec 10 19:41:49 2017 +0900
# Node ID 9766da17d816b8c919fc6df2ea6a493f533b615f
# Parent  85a8d0279d24d039a4f113179dcafac44a3eb93c
debugformat: embed raw values in JSON and template output

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -873,15 +873,18 @@ def debugformat(ui, repo, **opts):
     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')
diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -85,28 +85,28 @@ An upgrade of a repository created with 
   $ 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",


More information about the Mercurial-devel mailing list