Patchwork [1,of,2] progress: extract stubs to restart ferr.flush() and .write() on EINTR

login
register
mail settings
Submitter Yuya Nishihara
Date April 15, 2017, 10:19 a.m.
Message ID <087fef3472d6f204c8ef.1492251541@mimosa>
Download mbox | patch
Permalink /patch/20216/
State Accepted
Headers show

Comments

Yuya Nishihara - April 15, 2017, 10:19 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1492090045 -32400
#      Thu Apr 13 22:27:25 2017 +0900
# Node ID 087fef3472d6f204c8ef55c5257b9950aac35e72
# Parent  7c455aa99683ec6f7f24c24e11aaadfb3fe32fe3
progress: extract stubs to restart ferr.flush() and .write() on EINTR

Patch

diff --git a/mercurial/progress.py b/mercurial/progress.py
--- a/mercurial/progress.py
+++ b/mercurial/progress.py
@@ -157,14 +157,14 @@  class progbar(object):
             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 @@  class progbar(object):
         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)