--- 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
"""
--- a/tests/test-obsolete-divergent.t Sat Apr 14 00:41:44 2018 -0400
+++ b/tests/test-obsolete-divergent.t Mon Mar 26 17:00:12 2018 +0800
@@ -721,6 +721,11 @@
$ hg debugwhyunstable 1a2a9b5b0030
content-divergent: 70d5a63ca112acb3764bc1d7320ca90ea688d671 (draft) predecessor a178212c3433c4e77b573f6011e29affb8aefa33
+ $ hg log -r 1a2a9b5b0030 --hidden -T '{whyunstable}\n'
+ content-divergent: 4:70d5a63ca112 (draft) predecessor a178212c3433
+ $ hg log -r 1a2a9b5b0030 --hidden -T '{whyunstable%"{instability}:{divergentnodes} {reason} {node}\n"}'
+ content-divergent: 4:70d5a63ca112 (draft) predecessor a178212c3433c4e77b573f6011e29affb8aefa33
+
#if serve
$ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
--- a/tests/test-obsolete.t Sat Apr 14 00:41:44 2018 -0400
+++ b/tests/test-obsolete.t Mon Mar 26 17:00:12 2018 +0800
@@ -1044,6 +1044,15 @@
orphan: obsolete parent 3de5eca88c00aa039da7399a220f4a5221faa585
phase-divergent: immutable predecessor 245bde4270cd1072a27757984f9cda8ba26f08ca
+test whyunstable template keyword
+
+ $ hg log -r 50c51b361e60 -T '{whyunstable}\n'
+ orphan: obsolete parent 3de5eca88c00
+ phase-divergent: immutable predecessor 245bde4270cd
+ $ hg log -r 50c51b361e60 -T '{whyunstable%"{instability}: {reason} {node}\n"}'
+ orphan: obsolete parent 3de5eca88c00aa039da7399a220f4a5221faa585
+ phase-divergent: immutable predecessor 245bde4270cd1072a27757984f9cda8ba26f08ca
+
#if serve
$ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log