Patchwork [3,of,6] ui: simplify interface of low-level write() functions

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 4, 2018, 12:55 p.m.
Message ID <5825c9e9abddbe48b463.1541336123@mimosa>
Download mbox | patch
Permalink /patch/36358/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 4, 2018, 12:55 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541234170 -32400
#      Sat Nov 03 17:36:10 2018 +0900
# Node ID 5825c9e9abddbe48b4635178eaac5571e587f9c3
# Parent  27823240c017e4a7d474c93013c149d9c84d73c9
ui: simplify interface of low-level write() functions

_write() and _write_err() will be replaced with fout.write() and ferr.write()
respectively. This is the first step.

Patch

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -529,7 +529,7 @@  if pycompat.iswindows:
                         attr = mapcolor(int(sattr), attr)
                 ui.flush()
                 _kernel32.SetConsoleTextAttribute(stdout, attr)
-                writefunc(m.group(2), **opts)
+                writefunc(m.group(2))
                 m = re.match(ansire, m.group(3))
         finally:
             # Explicitly reset original attributes
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -960,13 +960,13 @@  class ui(object):
             if self._colormode is not None:
                 label = opts.get(r'label', '')
                 msgs = [self.label(a, label) for a in args]
-            write(*msgs, **opts)
+            write(b''.join(msgs))
 
-    def _write(self, *msgs, **opts):
+    def _write(self, data):
         # opencode timeblockedsection because this is a critical path
         starttime = util.timer()
         try:
-            self.fout.write(''.join(msgs))
+            self.fout.write(data)
         except IOError as err:
             raise error.StdioError(err)
         finally:
@@ -979,13 +979,12 @@  class ui(object):
         else:
             self._writenobuf(self._write_err, *args, **opts)
 
-    def _write_err(self, *msgs, **opts):
+    def _write_err(self, data):
         try:
             with self.timeblockedsection('stdio'):
                 if not getattr(self.fout, 'closed', False):
                     self.fout.flush()
-                for a in msgs:
-                    self.ferr.write(a)
+                self.ferr.write(data)
                 # stderr may be buffered under win32 when redirected to files,
                 # including stdout.
                 if not getattr(self.ferr, 'closed', False):