comparison mercurial/templater.py @ 26485:43bf9471fae9

templater: introduce {latesttag()} function to match a pattern (issue4184) This allows the latest class of tag to be found, such as a release candidate or final build, instead of just the absolute latest. It doesn't appear that the existing keyword can be given an optional argument. There is a keyword, function and filter for 'date', so it doesn't seem harmful to introduce a new function with the same name as an existing keyword. Most functions are pretty Mercurial agnostic, but there is {revset()} as precedent. Even though templatekw.getlatesttags() returns a single tuple, one entry of which is a list, it is simplest to present this as a list of tags instead of a single item, with each tag having a distance and change count attribute. It is also closer to how {latesttag} returns a list of tags, and how this function works when not given a '%' operator.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 23 Aug 2015 23:44:58 -0400
parents 0a5a774f5956
children 875e5d89dc86
comparison
equal deleted inserted replaced
26484:93c80e7ed8c8 26485:43bf9471fae9
510 raise error.ParseError(_("label expects two arguments")) 510 raise error.ParseError(_("label expects two arguments"))
511 511
512 # ignore args[0] (the label string) since this is supposed to be a a no-op 512 # ignore args[0] (the label string) since this is supposed to be a a no-op
513 yield args[1][0](context, mapping, args[1][1]) 513 yield args[1][0](context, mapping, args[1][1])
514 514
515 def latesttag(context, mapping, args):
516 """:latesttag([pattern]): The global tags matching the given pattern on the
517 most recent globally tagged ancestor of this changeset."""
518 if len(args) > 1:
519 # i18n: "latesttag" is a keyword
520 raise error.ParseError(_("latesttag expects at most one argument"))
521
522 pattern = None
523 if len(args) == 1:
524 pattern = stringify(args[0][0](context, mapping, args[0][1]))
525
526 return templatekw.showlatesttags(pattern, **mapping)
527
515 def localdate(context, mapping, args): 528 def localdate(context, mapping, args):
516 """:localdate(date[, tz]): Converts a date to the specified timezone. 529 """:localdate(date[, tz]): Converts a date to the specified timezone.
517 The default is local date.""" 530 The default is local date."""
518 if not (1 <= len(args) <= 2): 531 if not (1 <= len(args) <= 2):
519 # i18n: "localdate" is a keyword 532 # i18n: "localdate" is a keyword
731 "ifcontains": ifcontains, 744 "ifcontains": ifcontains,
732 "ifeq": ifeq, 745 "ifeq": ifeq,
733 "indent": indent, 746 "indent": indent,
734 "join": join, 747 "join": join,
735 "label": label, 748 "label": label,
749 "latesttag": latesttag,
736 "localdate": localdate, 750 "localdate": localdate,
737 "pad": pad, 751 "pad": pad,
738 "revset": revset, 752 "revset": revset,
739 "rstdoc": rstdoc, 753 "rstdoc": rstdoc,
740 "shortest": shortest, 754 "shortest": shortest,