compat: register a version of 'troubles' template that works with 4.6 API
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 04 Mar 2018 17:09:41 -0500
changeset 3516 359734049764
parent 3515 d5a824a5853f
child 3517 dc31ec3ef042
compat: register a version of 'troubles' template that works with 4.6 API Since showlist is deprecated, let us use compatlist.
hgext3rd/evolve/templatekw.py
--- a/hgext3rd/evolve/templatekw.py	Sun Mar 04 17:07:53 2018 -0500
+++ b/hgext3rd/evolve/templatekw.py	Sun Mar 04 17:09:41 2018 -0500
@@ -34,18 +34,26 @@
         return 'obsolete'
     return ''
 
-@eh.templatekw('troubles')
-def showtroubles(**args):
-    """List of strings. Evolution troubles affecting the changeset
-    (zero or more of "unstable", "divergent" or "bumped")."""
-    ctx = args['ctx']
-    try:
-        # specify plural= explicitly to trigger TypeError on hg < 4.2
-        return templatekw.showlist('trouble', ctx.instabilities(), args,
-                                   plural='troubles')
-    except TypeError:
-        return templatekw.showlist('trouble', ctx.instabilities(), plural='troubles',
-                                   **args)
+if util.safehasattr(templatekw, 'compatlist'):
+    @eh.templatekw('troubles', requires=set(['ctx', 'templ']))
+    def showtroubles(context, mapping):
+        ctx = context.resource(mapping, 'ctx')
+        return templatekw.compatlist(context, mapping, 'trouble',
+                                     ctx.instabilities(), plural='troubles')
+else:
+    # older template API in hg < 4.6
+    @eh.templatekw('troubles')
+    def showtroubles(**args):
+        """List of strings. Evolution troubles affecting the changeset
+        (zero or more of "unstable", "divergent" or "bumped")."""
+        ctx = args['ctx']
+        try:
+            # specify plural= explicitly to trigger TypeError on hg < 4.2
+            return templatekw.showlist('trouble', ctx.instabilities(), args,
+                                       plural='troubles')
+        except TypeError:
+            return templatekw.showlist('trouble', ctx.instabilities(), plural='troubles',
+                                       **args)
 
 if util.safehasattr(templatekw, 'showpredecessors'):
     templatekw.keywords["precursors"] = templatekw.showpredecessors