[PATCH 1 of 3] formatter: add support for functions in json

Mathias De Maré mathias.demare at gmail.com
Mon Aug 29 17:52:41 UTC 2016


# HG changeset patch
# User Mathias De Maré <mathias.demare at gmail.com>
# Date 1472483920 -7200
#      Mon Aug 29 17:18:40 2016 +0200
# Node ID fb88d0c87c2746bd84983f1005ed83276c6e9c68
# Parent  318e2b600b80e4ed3c6f37df46ec7544f60d4c0b
formatter: add support for functions in json

Some extensions (like largefiles) assign functions to configuration entries.
This was only possible without formatting so far.

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -193,6 +193,8 @@
     elif isinstance(v, (int, float)):
         return str(v)
     else:
+        if callable(v):
+            v = "<function %s>" % v.func_name
         return '"%s"' % encoding.jsonescape(v)
 
 class jsonformatter(baseformatter):


More information about the Mercurial-devel mailing list