Patchwork [2,of,2] templates: make divergentnodes in whyunstable keyword be a mappinglist too (RFC)

login
register
mail settings
Submitter Anton Shestakov
Date April 14, 2018, 11:43 a.m.
Message ID <6287c68bde7bcdc1dc26.1523706196@neuro>
Download mbox | patch
Permalink /patch/31014/
State Accepted
Headers show

Comments

Anton Shestakov - April 14, 2018, 11:43 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1523705764 -28800
#      Sat Apr 14 19:36:04 2018 +0800
# Node ID 6287c68bde7bcdc1dc260da9983ecc7fffc9ee20
# Parent  987c05eac1801d0b919c874280d03f9e8cccb411
templates: make divergentnodes in whyunstable keyword be a mappinglist too (RFC)

I'd like this to work, but it doesn't: "{divergentnodes}" show a178212c3433 as
the divergent node, and not 70d5a63ca112 (so the whole test case fails).
Yuya Nishihara - April 14, 2018, 12:09 p.m.
On Sat, 14 Apr 2018 19:43:16 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1523705764 -28800
> #      Sat Apr 14 19:36:04 2018 +0800
> # Node ID 6287c68bde7bcdc1dc260da9983ecc7fffc9ee20
> # Parent  987c05eac1801d0b919c874280d03f9e8cccb411
> templates: make divergentnodes in whyunstable keyword be a mappinglist too (RFC)

> I'd like this to work, but it doesn't: "{divergentnodes}" show a178212c3433 as
> the divergent node, and not 70d5a63ca112 (so the whole test case fails).

>      for entry in entries:
>          if entry.get('divergentnodes'):
> -            dnodes = entry['divergentnodes']
> -            entry['divergentnodes'] = ''.join(formatnode(dnode)
> -                                              for dnode in dnodes)
> +            dnodes = [{ctx: dnode} for dnode in entry['divergentnodes']]
                          ^^^
                          'ctx':

Anyway, _hybrid() is preferred for a list of items.
Anton Shestakov - April 14, 2018, 12:40 p.m.
On Sat, 14 Apr 2018 21:09:46 +0900
Yuya Nishihara <yuya@tcha.org> wrote:

> On Sat, 14 Apr 2018 19:43:16 +0800, Anton Shestakov wrote:
> > # HG changeset patch
> > # User Anton Shestakov <av6@dwimlabs.net>
> > # Date 1523705764 -28800
> > #      Sat Apr 14 19:36:04 2018 +0800
> > # Node ID 6287c68bde7bcdc1dc260da9983ecc7fffc9ee20
> > # Parent  987c05eac1801d0b919c874280d03f9e8cccb411
> > templates: make divergentnodes in whyunstable keyword be a mappinglist too (RFC)  
> 
> > I'd like this to work, but it doesn't: "{divergentnodes}" show a178212c3433 as
> > the divergent node, and not 70d5a63ca112 (so the whole test case fails).  
> 
> >      for entry in entries:
> >          if entry.get('divergentnodes'):
> > -            dnodes = entry['divergentnodes']
> > -            entry['divergentnodes'] = ''.join(formatnode(dnode)
> > -                                              for dnode in dnodes)
> > +            dnodes = [{ctx: dnode} for dnode in entry['divergentnodes']]  
>                           ^^^
>                           'ctx':

Ah. Yep, that was it.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -800,20 +800,17 @@  def showwhyunstable(context, mapping):
     """
     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)
+    mappinglist = templateutil.mappinglist
 
     for entry in entries:
         if entry.get('divergentnodes'):
-            dnodes = entry['divergentnodes']
-            entry['divergentnodes'] = ''.join(formatnode(dnode)
-                                              for dnode in dnodes)
+            dnodes = [{ctx: dnode} for dnode in entry['divergentnodes']]
+            tmpl = ' {rev}:{node|short} ({phase})'
+            entry['divergentnodes'] = mappinglist(dnodes, tmpl=tmpl)
 
     tmpl = '{instability}:{divergentnodes} {reason} {node|short}'
-    return templateutil.mappinglist(entries, tmpl=tmpl, sep='\n')
+    return mappinglist(entries, tmpl=tmpl, sep='\n')
 
 def loadkeyword(ui, extname, registrarobj):
     """Load template keyword from specified registrarobj
diff --git a/tests/test-obsolete-divergent.t b/tests/test-obsolete-divergent.t
--- a/tests/test-obsolete-divergent.t
+++ b/tests/test-obsolete-divergent.t
@@ -725,6 +725,8 @@  Use scmutil.cleanupnodes API to create d
   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
+  $ hg log -r 1a2a9b5b0030 --hidden -T '{whyunstable%"{instability}:{divergentnodes % " {node} ({phase})"} {reason} {node}\n"}'
+  content-divergent: 70d5a63ca112acb3764bc1d7320ca90ea688d671 (draft) predecessor a178212c3433c4e77b573f6011e29affb8aefa33
 
 #if serve