[PATCH 6 of 9 V3] template: compute user in obsfateusers
Yuya Nishihara
yuya at tcha.org
Wed Aug 23 14:56:08 UTC 2017
On Wed, 23 Aug 2017 16:31:21 +0200, Boris Feld wrote:
> On Wed, 2017-08-23 at 00:02 +0900, Yuya Nishihara wrote:
> > On Mon, 21 Aug 2017 10:43:58 +0200, Boris Feld wrote:
> > > # HG changeset patch
> > > # User Boris Feld <boris.feld at octobus.net>
> > > # Date 1499088840 -7200
> > > # Mon Jul 03 15:34:00 2017 +0200
> > > # Node ID 2fee3b06f7b09f35dcfa312b645cf94090c11fb9
> > > # Parent 66a2b0407c8cffedfae4897bd7a2f0e2d6a22363
> > > # EXP-Topic obsfatetemplate
> > > template: compute user in obsfateusers
> > > +def _successorsetusers(successorset, markers):
> > > + """ Returns a sorted list of markers users without duplicates
> > > + """
> > > + if not markers:
> > > + return {}
> > > +
> > > + # Check that user is present in meta
> > > + markersmeta = [dict(m[3]) for m in markers]
> > > + users = set(meta.get('user') for meta in markersmeta if
> > > meta.get('user'))
> > > +
> > > + return {'users': sorted(users)}
> >
> > [...]
> >
> > > + at templatefunc('obsfateusers(successors, markers)')
> > > +def obsfateusers(context, mapping, args):
> > > + """ Compute obsfate related information based on successors
> > > and markers
> > > + """
> > > + successors = evalfuncarg(context, mapping, args[0])
> > > + markers = evalfuncarg(context, mapping, args[1])
> > > + data = obsutil._successorsetusers(successors, markers)
> > > +
> > > + _hybrid = templatekw._hybrid
> > > +
> > > + def makemap(x):
> > > + return x
> > > +
> > > + def joinfmt(d):
> > > + return d
> > > +
> > > + return _hybrid(None, [data], makemap, joinfmt)
> >
> > Why isn't this a list of users, but a list of dict of list of users?
>
> It was a artifact from the previous version of the series. It was meant
> to permit this notation:
>
> obsfateusers(successors, markers) % "{if(users, " by {join(users, ",
> ")}")}"
>
> I've tried cleaning it, code is cleaner and the template is slighty
> less clean now:
>
> {if(obsfateusers(markers), " by {join(obsfateusers(markers), ", ")}")}
obsfateusers(markers) could be a templatealias or a keyword in mapfile.
# .hgrc
[templatealias]
x = obsfateusers(markers)
# mapfile
x = '{join(obsfateusers(markers), ", ")}'
... = '{if(x, " by {x}")}'
I don't think it's good idea to design a template keyword/function for
a specific use case.
More information about the Mercurial-devel
mailing list