Patchwork [2,of,6] color: inline the 'showlabel' method

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 22, 2017, 4:54 p.m.
Message ID <f53e95ec986616a48a3a.1487782473@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18718/
State Superseded
Delegated to: Yuya Nishihara
Headers show

Comments

Pierre-Yves David - Feb. 22, 2017, 4:54 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1487589203 -3600
#      Mon Feb 20 12:13:23 2017 +0100
# Node ID f53e95ec986616a48a3a8e67e5a9674b8a684d6e
# Parent  d32d64e7e9f084bf01cbac178ad2c2e74e130f9d
# EXP-Topic color
color: inline the 'showlabel' method

This function is quite simple and only have one call siteā€¦ located a handful of line
under the definition. We inline the function for the sake of simplicity. One of
the motivation to do that now is that it reduce the amount of new method we
will have to add to the core 'ui' class for color support.

Patch

diff -r d32d64e7e9f0 -r f53e95ec9866 hgext/color.py
--- a/hgext/color.py	Mon Feb 20 12:12:08 2017 +0100
+++ b/hgext/color.py	Mon Feb 20 12:13:23 2017 +0100
@@ -328,21 +328,18 @@  class colorui(uimod.ui):
             return super(colorui, self).write_err(
                 *[self.label(a, label) for a in args], **opts)
 
-    def showlabel(self, msg, label):
-        if label and msg:
-            if msg[-1] == '\n':
-                return "[%s|%s]\n" % (label, msg[:-1])
-            else:
-                return "[%s|%s]" % (label, msg)
-        else:
-            return msg
-
     def label(self, msg, label):
         if self._colormode is None:
             return super(colorui, self).label(msg, label)
 
         if self._colormode == 'debug':
-            return self.showlabel(msg, label)
+            if label and msg:
+                if msg[-1] == '\n':
+                    return "[%s|%s]\n" % (label, msg[:-1])
+                else:
+                    return "[%s|%s]" % (label, msg)
+            else:
+                return msg
 
         effects = []
         for l in label.split():