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

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 10, 2017, 10:58 a.m.
Message ID <9766da17d816b8c919fc.1512903496@mimosa>
Download mbox | patch
Permalink /patch/26196/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 10, 2017, 10:58 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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

Patch

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",