changeset 32048:c3ef33fd0058

progress: extract stubs to restart ferr.flush() and .write() on EINTR
author Yuya Nishihara <yuya@tcha.org>
date Thu, 13 Apr 2017 22:27:25 +0900
parents 458f7294dfee
children ed42e00a5c4e
files mercurial/progress.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/progress.py	Sat Feb 25 19:36:02 2017 +0900
+++ b/mercurial/progress.py	Thu Apr 13 22:27:25 2017 +0900
@@ -157,14 +157,14 @@
             out = spacejoin(head, prog, tail)
         else:
             out = spacejoin(head, tail)
-        self.ui.ferr.write('\r' + encoding.trim(out, termwidth))
+        self._writeerr('\r' + encoding.trim(out, termwidth))
         self.lasttopic = topic
-        self.ui.ferr.flush()
+        self._flusherr()
 
     def clear(self):
         if not self.printed or not self.lastprint or not shouldprint(self.ui):
             return
-        self.ui.ferr.write('\r%s\r' % (' ' * self.width()))
+        self._writeerr('\r%s\r' % (' ' * self.width()))
         if self.printed:
             # force immediate re-paint of progress bar
             self.lastprint = 0
@@ -175,9 +175,15 @@
         if self.ui.configbool('progress', 'clear-complete', default=True):
             self.clear()
         else:
-            self.ui.ferr.write('\n')
+            self._writeerr('\n')
+        self._flusherr()
+
+    def _flusherr(self):
         self.ui.ferr.flush()
 
+    def _writeerr(self, msg):
+        self.ui.ferr.write(msg)
+
     def width(self):
         tw = self.ui.termwidth()
         return min(int(self.ui.config('progress', 'width', default=tw)), tw)