From patchwork Sun Oct 5 01:05:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [1,of,6] color: omit debug label output on empty strings From: =?utf-8?q?Jordi_Guti=C3=A9rrez_Hermoso?= X-Patchwork-Id: 6121 Message-Id: <9f503562486cca1a723d.1412471150@Iris> To: mercurial-devel@selenic.com Date: Sat, 04 Oct 2014 21:05:50 -0400 # HG changeset patch # User Jordi GutiƩrrez Hermoso # 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