diff mercurial/templatekw.py @ 37685:76cd5816268e

templates: add whyunstable template keyword
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 26 Mar 2018 17:00:12 +0800
parents 49a8c2cc7978
children b1b1b0626f59
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sat Apr 14 00:41:44 2018 -0400
+++ b/mercurial/templatekw.py	Mon Mar 26 17:00:12 2018 +0800
@@ -793,6 +793,28 @@
         return 'verbose'
     return ''
 
+@templatekeyword('whyunstable', requires={'repo', 'ctx'})
+def showwhyunstable(context, mapping):
+    """List of dicts explaining all instabilities of a changeset.
+    (EXPERIMENTAL)
+    """
+    repo = context.resource(mapping, 'repo')
+    ctx = context.resource(mapping, 'ctx')
+
+    def formatnode(ctx):
+        return ' %s (%s)' % (scmutil.formatchangeid(ctx), ctx.phasestr())
+
+    entries = obsutil.whyunstable(repo, ctx)
+
+    for entry in entries:
+        if entry.get('divergentnodes'):
+            dnodes = entry['divergentnodes']
+            entry['divergentnodes'] = ''.join(formatnode(dnode)
+                                              for dnode in dnodes)
+
+    tmpl = '{instability}:{divergentnodes} {reason} {node|short}'
+    return templateutil.mappinglist(entries, tmpl=tmpl, sep='\n')
+
 def loadkeyword(ui, extname, registrarobj):
     """Load template keyword from specified registrarobj
     """