changeset 22763:7ebf91426f6a

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.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Fri, 03 Oct 2014 19:47:57 -0400
parents 05b3238ba901
children 1e2f54a149e8
files hgext/color.py tests/test-status-color.t
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Sat Oct 04 17:22:22 2014 +0900
+++ b/hgext/color.py	Fri Oct 03 19:47:57 2014 -0400
@@ -407,8 +407,8 @@
                 *[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)
--- a/tests/test-status-color.t	Sat Oct 04 17:22:22 2014 +0900
+++ b/tests/test-status-color.t	Fri Oct 03 19:47:57 2014 -0400
@@ -152,6 +152,11 @@
   [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