[PATCH 1 of 2] templates: add whyunstable template keyword

Yuya Nishihara yuya at tcha.org
Mon Mar 26 09:13:18 EDT 2018


On Mon, 26 Mar 2018 19:55:20 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6 at dwimlabs.net>
> # Date 1522054812 -28800
> #      Mon Mar 26 17:00:12 2018 +0800
> # Node ID 123d9e4d706909c8912f11acee292735c0fb283c
> # Parent  6f570c501e3ebc3d9b59920f50ed7523d93cb847
> templates: add whyunstable template keyword

> + at templatekeyword('whyunstable', requires={'repo', 'ctx', 'templ'})
                                                            ^^^^^^^

'templ' is no longer needed.

> +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())
> +
> +    def formatentry(entry):
> +        dnodes = ''
> +        if entry.get('divergentnodes'):
> +            dnodes = ' '.join(formatnode(ctx)
> +                              for ctx in entry['divergentnodes']) + ' '
> +        return '%s: %s%s %s' % (entry['instability'],
> +                                dnodes,
> +                                entry['reason'],
> +                                scmutil.formatchangeid(repo[entry['node']]))
> +
> +    def makemap(entry):
> +        item = {'ctx': repo[entry['node']], 'revcache': {}}
                                               ^^^^^^^^^^^^^^

'revcache' is no longer needed.

Perhaps, obsutil.whyunstable() can put 'ctx' instead of 'node'?

> +        item.update(entry)
> +        if item.get('divergentnodes'):
> +            dnhybrid = _hybrid(None, item['divergentnodes'],
> +                               lambda x: {'ctx': x, 'revcache': {}},
> +                               formatnode)

Perhaps showrevslist() can be used. Each hybrid value has to be a printable
object such as int.

> +            item['divergentnodes'] = dnhybrid
> +        return item
> +
> +    entries = obsutil.whyunstable(repo, ctx)
> +    return _hybrid(None, entries, makemap, formatentry)

It isn't correct to wrap a list of template mappings by _hybrid. Instead,
makemap() has to build a mapping dict from a printable value.

Can you hold off this series for 2-3 weeks? I have long series which will
add a wrapper for a list of template mappings. Basically it will allow us
to write the default string representation as template:

  return mappinglist(entries, tmpl='{instability}: {divergentnodes % ...')


More information about the Mercurial-devel mailing list