[PATCH 4 of 9 V4] template: add minimal obsfate template function

Yuya Nishihara yuya at tcha.org
Fri Aug 25 09:59:11 EDT 2017


On Wed, 23 Aug 2017 17:18:38 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1502987171 -7200
> #      Thu Aug 17 18:26:11 2017 +0200
> # Node ID c2702967b47010d10ee0b8cf9ee633928d4b6214
> # Parent  e8087ac6f8c52088233f5d499133de7f881a0c12
> # EXP-Topic obsfatetemplate
> template: add minimal obsfate template function

Queued up to this, thanks.

> +def successorsandmarkers(repo, ctx):
> +    """compute the raw data needed for computing obsfate
> +    Returns a list of dict, one dict per successors set
> +    """
> +    if not ctx.obsolete():
> +        return None

Nit: why returning None instead of [] ?

> +    ssets = successorssets(repo, ctx.node(), closest=True)
> +
> +    values = []
> +    for sset in ssets:
> +        values.append({'successors': sset, 'markers': sset.markers})
> +
> +    return values

This function seems not useful because showsuccsandmarkers() have to
reconstruct a list anyway.

> + at templatekeyword("succsandmarkers")
> +def showsuccsandmarkers(repo, ctx, **args):
> +    """Returns a list of dict for each final successor of ctx.
> +
> +    The dict contains successors node id in "successors" keys and the list of
> +    obs-markers from ctx to the set of successors in "markers"
> +
> +    (EXPERIMENTAL)
> +    """
> +
> +    values = obsutil.successorsandmarkers(repo, ctx)
> +
> +    if values is None:
> +        values = []
> +
> +    # Format successors and markers to avoid exposing binary to templates
> +    hex = nodemod.hex

Removed this since hex is imported as symbol.

> +    data = []
> +    for i in values:
> +        # Format successors
> +        successors = i['successors']
> +
> +        successors = [hex(n) for n in successors]
> +        successors = _hybrid(None, successors,
> +                             lambda x: {'ctx': repo[x], 'revcache': {}},
> +                             lambda d: _formatrevnode(d['ctx']))
> +
> +        # Format markers
> +        finalmarkers = []
> +        for m in i['markers']:
> +            hexprec = hex(m[0])
> +            hexsucs = tuple(hex(n) for n in m[1])
> +            hexparents = None
> +            if m[5] is not None:
> +                hexparents = tuple(hex(n) for n in m[5])
> +            newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:]
> +            finalmarkers.append(newmarker)
> +
> +        data.append({'successors': successors, 'markers': finalmarkers})
> +
> +    f = _showlist('succsandmarkers', data, args)
> +    return _hybrid(f, data, lambda x: x, lambda d: d)

This _hybrid object and 'joinfmt=lambda d: d' don't make sense, but I have no
idea how {succsandmarkers} should be rendered. So let's revisit it later.


More information about the Mercurial-devel mailing list