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

2018-04-14 Thread Anton Shestakov
On Sat, 14 Apr 2018 21:09:46 +0900
Yuya Nishihara  wrote:

> On Sat, 14 Apr 2018 19:43:16 +0800, Anton Shestakov wrote:
> > # HG changeset patch
> > # User Anton Shestakov 
> > # 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.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2018-04-14 Thread Yuya Nishihara
On Sat, 14 Apr 2018 19:43:16 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov 
> # 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.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2018-04-14 Thread Anton Shestakov
# HG changeset patch
# User Anton Shestakov 
# 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).

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
 
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel