[PATCH 10 of 12] template: rename label to color but leave alias for backwards compatibility

Sean Farley sean.michael.farley at gmail.com
Mon Aug 18 16:18:06 CDT 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1402609284 25200
#      Thu Jun 12 14:41:24 2014 -0700
# Node ID f49b99874b05d0a902f8ed02201d9e57fc81c684
# Parent  186ccd3d9042c0c5ec8cb9b9b4d58a7386ea1c65
template: rename label to color but leave alias for backwards compatibility

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -393,14 +393,14 @@ class colorui(uimod.ui):
         if effects:
             return '\n'.join([render_effects(s, effects)
                               for s in msg.split('\n')])
         return msg
 
-def templatelabel(context, mapping, args):
+def templatecolor(context, mapping, args):
     if len(args) != 2:
-        # i18n: "label" is a keyword
-        raise error.ParseError(_("label expects two arguments"))
+        # i18n: "color" is a keyword
+        raise error.ParseError(_("color expects two arguments"))
 
     # add known effects to the mapping so symbols like 'red', 'bold',
     # etc. don't need to be quoted
     mapping.update(dict([(k, k) for k in _effects]))
 
@@ -409,16 +409,16 @@ def templatelabel(context, mapping, args
     # apparently, repo could be a string that is the favicon?
     repo = mapping.get('repo', '')
     if isinstance(repo, str):
         return thing
 
-    label = templater._evalifliteral(args[0], context, mapping)
+    color = templater._evalifliteral(args[0], context, mapping)
 
     thing = templater.stringify(thing)
-    label = templater.stringify(label)
+    color = templater.stringify(color)
 
-    return repo.ui.label(thing, label)
+    return repo.ui.label(thing, color)
 
 def uisetup(ui):
     if ui.plain():
         return
     if not isinstance(ui, colorui):
@@ -430,11 +430,13 @@ def uisetup(ui):
         if mode:
             extstyles()
             configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)
     extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
-    templater.funcs['label'] = templatelabel
+    templater.funcs['color'] = templatecolor
+    # backwards compatibility before 3.0
+    templater.funcs['label'] = templatecolor
 
 def extsetup(ui):
     commands.globalopts.append(
         ('', 'color', 'auto',
          # i18n: 'always', 'auto', and 'never' are keywords and should
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -349,16 +349,16 @@ def join(context, mapping, args):
             first = False
         else:
             yield joiner
         yield x
 
-def label(context, mapping, args):
+def color(context, mapping, args):
     if len(args) != 2:
-        # i18n: "label" is a keyword
-        raise error.ParseError(_("label expects two arguments"))
+        # i18n: "color" is a keyword
+        raise error.ParseError(_("color expects two arguments"))
 
-    # ignore args[0] (the label string) since this is supposed to be a a no-op
+    # ignore args[0] (the color string) since this is supposed to be a a no-op
     yield _evalifliteral(args[1], context, mapping)
 
 def revset(context, mapping, args):
     """usage: revset(query[, formatargs...])
     """
@@ -509,17 +509,18 @@ methods = {
     "func": buildfunc,
     }
 
 funcs = {
     "date": date,
+    "color": color,
     "fill": fill,
     "get": get,
     "if": if_,
     "ifcontains": ifcontains,
     "ifeq": ifeq,
     "join": join,
-    "label": label,
+    "label": color, # backwards compatibility before 3.1
     "pad": pad,
     "revset": revset,
     "rstdoc": rstdoc,
     "shortest": shortest,
     "startswith": startswith,


More information about the Mercurial-devel mailing list