templater: fix cbor() filter to accept smartset
authorYuya Nishihara <yuya@tcha.org>
Sun, 15 Mar 2020 22:01:38 +0900
changeset 44590 e3e44e6e7245
parent 44589 fc1fa3a07af6
child 44591 1f81f680912f
templater: fix cbor() filter to accept smartset So the wrapper type can return a bare smartset.
mercurial/templatefilters.py
mercurial/templateutil.py
--- a/mercurial/templatefilters.py	Sun Mar 15 15:12:44 2020 +0900
+++ b/mercurial/templatefilters.py	Sun Mar 15 22:01:38 2020 +0900
@@ -18,6 +18,7 @@
     node,
     pycompat,
     registrar,
+    smartset,
     templateutil,
     url,
     util,
@@ -108,6 +109,9 @@
 @templatefilter(b'cbor')
 def cbor(obj):
     """Any object. Serializes the object to CBOR bytes."""
+    if isinstance(obj, smartset.abstractsmartset):
+        # cborutil is stricter about type than json() filter
+        obj = list(obj)
     return b''.join(cborutil.streamencode(obj))
 
 
--- a/mercurial/templateutil.py	Sun Mar 15 15:12:44 2020 +0900
+++ b/mercurial/templateutil.py	Sun Mar 15 22:01:38 2020 +0900
@@ -474,7 +474,7 @@
         return bool(self._revs)
 
     def tovalue(self, context, mapping):
-        return list(self._revs)
+        return self._revs
 
 
 class _mappingsequence(wrapped):