[PATCH 1 of 6] color: omit debug label output on empty strings
Jordi Gutiérrez Hermoso
jordigh at octave.org
Sat Oct 4 20:05:50 CDT 2014
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh at octave.org>
# Date 1412380077 14400
# Fri Oct 03 19:47:57 2014 -0400
# Node ID 9f503562486cca1a723de4230d9174e005051f82
# Parent 278968c64185b30b99713f14c349c04e1e3f6131
color: omit debug label output on empty strings
This is most noticeable when using custom templates. Before this
patch, a template like {label("foo.bar", baz)} would emit
[foo.bar|]
whenever baz was empty. This cset simply omits all output when baz is
empty.
diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -407,8 +407,8 @@ class colorui(uimod.ui):
*[self.label(str(a), label) for a in args], **opts)
def showlabel(self, msg, label):
- if label:
- if msg and msg[-1] == '\n':
+ if label and msg:
+ if msg[-1] == '\n':
return "[%s|%s]\n" % (label, msg[:-1])
else:
return "[%s|%s]" % (label, msg)
diff --git a/tests/test-status-color.t b/tests/test-status-color.t
--- a/tests/test-status-color.t
+++ b/tests/test-status-color.t
@@ -152,6 +152,11 @@ Make sure ui.formatted=False works
[log.date|date: Thu Jan 01 00:00:00 1970 +0000]
[log.summary|summary: initial checkin]
+Labels on empty strings should not be displayed, labels on custom
+templates should be.
+
+ $ hg log --color=debug -T '{label("my.label",author)}\n{label("skipped.label","")}'
+ [my.label|test]
$ touch modified added unknown ignored
$ hg add added
$ hg remove removed
More information about the Mercurial-devel
mailing list