Patchwork [08,of,13,V2] ui: extract the low level part of 'write' in a dedicated function

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 24, 2017, 10:09 p.m.
Message ID <9ce40e16b21c0e69d345.1487974182@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18760/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 24, 2017, 10:09 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1487960820 -3600
#      Fri Feb 24 19:27:00 2017 +0100
# Node ID 9ce40e16b21c0e69d345722edf79eb2a680d33f7
# Parent  d5355608d838bda4e67f5855bea85a7e1b2806c0
# EXP-Topic color
ui: extract the low level part of 'write' in a dedicated function

We are about to add some extra logic related to color. That logic will need to
access the low level layer of ui doing the actual write to a stream. (eg:
'win32print'). We extract this logic into a private method for this purpose.

Patch

diff -r d5355608d838 -r 9ce40e16b21c mercurial/ui.py
--- a/mercurial/ui.py	Fri Feb 24 21:34:07 2017 +0100
+++ b/mercurial/ui.py	Fri Feb 24 19:27:00 2017 +0100
@@ -796,11 +796,14 @@  class ui(object):
         if self._buffers and not opts.get('prompt', False):
             self._buffers[-1].extend(a for a in args)
         else:
+            self._write(*args, **opts)
+
+    def _write(self, *msgs, **opts):
             self._progclear()
             # opencode timeblockedsection because this is a critical path
             starttime = util.timer()
             try:
-                for a in args:
+                for a in msgs:
                     self.fout.write(a)
             finally:
                 self._blockedtimes['stdio_blocked'] += \