On Fri, 2017-08-25 at 23:08 +0900, Yuya Nishihara wrote: > On Wed, 23 Aug 2017 17:18:41 +0200, Boris Feld wrote: > > # HG changeset patch > > # User Boris Feld <boris.f...@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) > > > > +@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.
I have send a V5 series with modifications according to your recommendations. Thank you very much for your reviews! I tried using hybrid list in obsfatedate but it seems to crash because obsmarker date are tuple. The end of the traceback is: + File ".../mercurial/mercurial/templatefilters.py", line 360, in stringify + return "".join([stringify(t) for t in thing if t is not None]) + File ".../mercurial/mercurial/templatekw.py", line 55, in _defaultgen + yield self.joinfmt(d) + File ".../mercurial/mercurial/templatekw.py", line 81, in <lambda> + return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name]) + TypeError: not all arguments converted during string formatting + [1] It seems to be because of joinfmt and I'm not sure what would be the best way to workaround. > > > +@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. _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel