[PATCH 12 of 12] templater: add a method to list labels in a namespace
Sean Farley
sean.michael.farley at gmail.com
Mon Aug 18 16:18:08 CDT 2014
# 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
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,
More information about the Mercurial-devel
mailing list