Patchwork [1,of,7] ui: pass in file object to _writenobuf()

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 6, 2018, 2:21 p.m.
Message ID <678a5ecd68c74a760449.1541514090@mimosa>
Download mbox | patch
Permalink /patch/36430/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 6, 2018, 2:21 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541235377 -32400
#      Sat Nov 03 17:56:17 2018 +0900
# Node ID 678a5ecd68c74a760449b7c0297b93d98f1af429
# Parent  cbd251d479bb67d77f9b77a017a22632af2f77da
ui: pass in file object to _writenobuf()

See the subsequent patches for why. The "if" block in _writenobuf() will
be removed soon.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -947,10 +947,16 @@  class ui(object):
             else:
                 self._buffers[-1].extend(args)
         else:
-            self._writenobuf(self._write, *args, **opts)
+            self._writenobuf(self.fout, *args, **opts)
 
-    def _writenobuf(self, write, *args, **opts):
+    def _writenobuf(self, dest, *args, **opts):
         self._progclear()
+        if dest is self.fout:
+            write = self._write
+        elif dest is self.ferr:
+            write = self._write_err
+        else:
+            raise error.ProgrammingError('unsupported file to write')
         msg = b''.join(args)
 
         # opencode timeblockedsection because this is a critical path
@@ -979,7 +985,7 @@  class ui(object):
         if self._bufferstates and self._bufferstates[-1][0]:
             self.write(*args, **opts)
         else:
-            self._writenobuf(self._write_err, *args, **opts)
+            self._writenobuf(self.ferr, *args, **opts)
 
     def _write_err(self, data):
         try:
@@ -1343,7 +1349,7 @@  class ui(object):
         if not self.interactive():
             self.write(msg, ' ', default or '', "\n")
             return default
-        self._writenobuf(self._write, msg, label='ui.prompt')
+        self._writenobuf(self.fout, msg, label='ui.prompt')
         self.flush()
         try:
             r = self._readline()