formatter: fix handling of None value in templater mapping stable
authorYuya Nishihara <yuya@tcha.org>
Sun, 27 Oct 2019 12:49:09 +0900
branchstable
changeset 43337 7e20b705da5b
parent 43336 a71578ec6257
child 43338 08189f3acbc6
formatter: fix handling of None value in templater mapping For historical reasons, None in mapping dict means there's no such keyword, and falls back to b"". That's fine in log templates where mapping item is generally a callable returning a value (which may be None,) but the formatter directly puts an "evaluated" value in the mapping. So the None value has to be lifted to wrappedvalue(None) to avoid confusion in the template engine.
mercurial/formatter.py
tests/test-config.t
--- a/mercurial/formatter.py	Sun Oct 27 12:36:52 2019 +0900
+++ b/mercurial/formatter.py	Sun Oct 27 12:49:09 2019 +0900
@@ -515,6 +515,10 @@
         if part not in self._parts:
             return
         ref = self._parts[part]
+        # None can't be put in the mapping dict since it means <unset>
+        for k, v in item.items():
+            if v is None:
+                item[k] = templateutil.wrappedvalue(v)
         self._out.write(self._t.render(ref, item))
 
     @util.propertycache
--- a/tests/test-config.t	Sun Oct 27 12:36:52 2019 +0900
+++ b/tests/test-config.t	Sun Oct 27 12:49:09 2019 +0900
@@ -122,7 +122,7 @@
   ]
   $ hg config --config auth.cookiefile= auth -T'json(defaultvalue)'
   [
-   {"defaultvalue": ""}
+   {"defaultvalue": null}
   ]
   $ hg config --config auth.cookiefile= auth -T'{defaultvalue}\n'