Patchwork [2,of,4] templater: fix cbor() filter to accept smartset

login
register
mail settings
Submitter Yuya Nishihara
Date March 24, 2020, 2:42 p.m.
Message ID <2149f8b5c2eeb0cab6cc.1585060954@mimosa>
Download mbox | patch
Permalink /patch/45871/
State Accepted
Headers show

Comments

Yuya Nishihara - March 24, 2020, 2:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1584277298 -32400
#      Sun Mar 15 22:01:38 2020 +0900
# Node ID 2149f8b5c2eeb0cab6cc6aafb06db7cb7370253d
# Parent  22fa586e96c80e85f433565e39b14b17993310b6
templater: fix cbor() filter to accept smartset

So the wrapper type can return a bare smartset.

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -18,6 +18,7 @@  from . import (
     node,
     pycompat,
     registrar,
+    smartset,
     templateutil,
     url,
     util,
@@ -108,6 +109,9 @@  def basename(path):
 @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))
 
 
diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -474,7 +474,7 @@  class revslist(wrapped):
         return bool(self._revs)
 
     def tovalue(self, context, mapping):
-        return list(self._revs)
+        return self._revs
 
 
 class _mappingsequence(wrapped):