[PATCH 12 of 12] templater: add a method to list labels in a namespace

Augie Fackler raf at durin42.com
Tue Aug 19 09:05:10 CDT 2014


On Mon, Aug 18, 2014 at 04:18:08PM -0500, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley at gmail.com>
> # Date 1408394323 18000
> #      Mon Aug 18 15:38:43 2014 -0500
> # Node ID fe9b72aa7e160e690813cfe4242b013fb147937e
> # Parent  e1ab9da20be237323a1340efa16b58b03525596f
> templater: add a method to list labels in a namespace

I don't quite see the why of this series - is it so we can add other
types of labels to a changeset without having to do a bunch of
tapdancing? How would that be useful?

(The generality is kind of nice, and I can sort of see a use for
remotebranches in that a remotebranch could become a non-tag label,
but I'm not sure I'm sold that it'd be worth doing there, because then
you'd still have to wire in some lookup mechanics.)

>
> diff --git a/mercurial/templater.py b/mercurial/templater.py
> --- a/mercurial/templater.py
> +++ b/mercurial/templater.py
> @@ -357,10 +357,23 @@ def color(context, mapping, args):
>          raise error.ParseError(_("color expects two arguments"))
>
>      # ignore args[0] (the color string) since this is supposed to be a a no-op
>      yield _evalifliteral(args[1], context, mapping)
>
> +def labels(context, mapping, args):
> +    if len(args) != 1:
> +        # i18n: "label" is a keyword
> +        raise error.ParseError(_("labels expects one argument"))
> +
> +    ctx = mapping['ctx']
> +    repo = ctx._repo
> +    namespace = args[0][1]
> +    l = sorted(l[0] for l in repo.nodelabels(ctx.node())
> +               if l[1] == namespace)
> +
> +    return templatekw.showlist('label', l, **mapping)
> +
>  def revset(context, mapping, args):
>      """usage: revset(query[, formatargs...])
>      """
>      if not len(args) > 0:
>          # i18n: "revset" is a keyword
> @@ -517,10 +530,11 @@ funcs = {
>      "if": if_,
>      "ifcontains": ifcontains,
>      "ifeq": ifeq,
>      "join": join,
>      "label": color, # backwards compatibility before 3.1
> +    "labels": labels,
>      "pad": pad,
>      "revset": revset,
>      "rstdoc": rstdoc,
>      "shortest": shortest,
>      "startswith": startswith,
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list