[PATCH 9 of 9] template: use template-engine for obsfate

Yuya Nishihara yuya at tcha.org
Fri Jul 7 08:09:50 EDT 2017


On Thu, 06 Jul 2017 23:50:17 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1499085172 -7200
> #      Mon Jul 03 14:32:52 2017 +0200
> # Node ID e18d8e61b7260e246a82727c8cde01f936692cff
> # Parent  098585d4fbc88dc54513e12fa306d0e52ea2b323
> # EXP-Topic obsfatetemplate
> template: use template-engine for obsfate
> 
> Try to replace the obsfateprinter part by "sub-templates".
> 
> The code is hacky, I've tried to use at maximum the template engine but the
> raw data-structure doesn't seems well supported:
> 
>     [{'markers': [{}, {}, ...], 'successors': [A, ...], 'verb': '', ...}, ...]
> 
> I've put this changeset at the end so the beginning of the serie might be
> accepted without it. Even without this changeset, we already have good tests
> and the right structure for the computation of obsfate data.
> 
> diff -r 098585d4fbc8 -r e18d8e61b726 mercurial/templatekw.py
> --- a/mercurial/templatekw.py	Mon Jul 03 17:38:56 2017 +0200
> +++ b/mercurial/templatekw.py	Mon Jul 03 14:32:52 2017 +0200
> @@ -699,6 +699,32 @@
>  
>      return "; ".join(lines)
>  
> +def obsfatedefaulttempl(ui):
> +    """ Returns a dict with the default templates for obs fate
> +    """
> +    # Prepare templates
> +    verbtempl = '{verb}'
> +    usertempl = '{if(users, " by {join(users, ", ")}")}'
> +    succtempl = '{if(successors, " as ")}{successors}' # Bypass if limitation
> +    datetempleq = ' (at {min_date|isodate})'
> +    datetemplnoteq = ' (between {min_date|isodate} and {max_date|isodate})'
> +
> +    datetempl = '{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}'
> +    datetempl = datetempl % (datetempleq, datetemplnoteq)
> +
> +    optionalusertempl = usertempl
> +    username = _getusername(ui)
> +    if username is not None:
> +        optionalusertempl = ('{ifeq(join(users, "\0"), "%s", "", "%s")}'
> +                             % (username, usertempl))
> +
> +    # Assemble them
> +    return {
> +        'obsfate_quiet': verbtempl + succtempl,
> +        'obsfate': verbtempl + optionalusertempl + succtempl,
> +        'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl,
> +    }

This makes me feel you're doing things in wrong layer. In principle, template
keywords provide primitive data, which are pretty-printed by using user/stock
templates (e.g. templates/map-cmdline.default.)


More information about the Mercurial-devel mailing list