Patchwork [1,of,6] color: omit debug label output on empty strings

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Oct. 5, 2014, 1:05 a.m.
Message ID <9f503562486cca1a723d.1412471150@Iris>
Download mbox | patch
Permalink /patch/6121/
State Accepted
Commit 7ebf91426f6aa95bef38adf533358e8a1104822c
Headers show

Comments

Jordi Gutiérrez Hermoso - Oct. 5, 2014, 1:05 a.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@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.

Patch

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