[PATCH 7 of 9 V4] template: compute dates in obsfatedate

Yuya Nishihara yuya at tcha.org
Fri Aug 25 10:08:23 EDT 2017


On Wed, 23 Aug 2017 17:18:41 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1499088850 -7200
> #      Mon Jul 03 15:34:10 2017 +0200
> # Node ID b8b8b5bd728a5fb9fa847d56dd489c77a054b5ee
> # Parent  fc257b24c35c492591f348b039d9e3f9488118a8
> # EXP-Topic obsfatetemplate
> template: compute dates in obsfatedate
> 
> Extract the dates from obsmarkers. Compute the min and max date from the
> obsmarker range list.
> 
> diff -r fc257b24c35c -r b8b8b5bd728a mercurial/obsutil.py
> --- a/mercurial/obsutil.py	Mon Jul 03 15:34:00 2017 +0200
> +++ b/mercurial/obsutil.py	Mon Jul 03 15:34:10 2017 +0200
> @@ -587,6 +587,11 @@
>  
>      return sorted(users)
>  
> +def _markersdates(markers):
> +    """returns the list of dates for a list of markers
> +    """
> +    return [m[4] for m in markers]
> +
>  def successorsandmarkers(repo, ctx):
>      """compute the raw data needed for computing obsfate
>      Returns a list of dict, one dict per successors set
> diff -r fc257b24c35c -r b8b8b5bd728a mercurial/templater.py
> --- a/mercurial/templater.py	Mon Jul 03 15:34:00 2017 +0200
> +++ b/mercurial/templater.py	Mon Jul 03 15:34:10 2017 +0200
> @@ -888,6 +888,55 @@
>      data = obsutil._markersusers(markers)
>      return templatekw._hybrid(None, data, lambda x: x, lambda d: d)
>  
> + at templatefunc('obsfatedate(markers)')
> +def obsfatedate(context, mapping, args):
> +    """ Compute obsfate related information based on markers
> +
> +    (EXPERIMENTAL)
> +    """
> +    if not len(args) == 1:
> +        # i18n: "obsfatedate" is a keyword
> +        raise error.ParseError(_("obsfatedate expects one arguments"))
> +
> +    markers = evalfuncarg(context, mapping, args[0])
> +    if not isinstance(markers, collections.Iterable):
> +        # i18n: "obsfatedate" is a keyword
> +        errmsg = "obsfatedate first argument should be an iterable"
> +        raise error.ParseError(errmsg)
> +
> +    data = obsutil._markersdates(markers)
> +    return templatekw._hybrid(None, data, lambda x: x, lambda d: d)

Perhaps, hybridlist() can be used.

> + at templatefunc('min(iterable)')
> +def tmplmin(context, mapping, args, **kwargs):

Nit: the other functions are named as if_, dict_, etc., and roughly sorted
alphabetically.

> +    """ Return the min of an iterable
> +    """
> +    if not len(args) == 1:
> +        # i18n: "min" is a keyword
> +        raise error.ParseError(_("min expects one arguments"))
> +
> +    iterable = evalfuncarg(context, mapping, args[0])
> +    if not isinstance(iterable, collections.Iterable):
> +        # i18n: "obsfatedate" is a keyword
                   ^^^^^^^^^^^^^
Outdated comment.

> +        raise error.ParseError(_("min first argument should be an iterable"))
> +
> +    return min(iterable)

An empty list is also invalid. Perhaps we can catch TypeError and
ValueError instead of testing if the argument is an iterable.


More information about the Mercurial-devel mailing list