changeset 41284:b0e3f2d7c143

ui: move protectedstdio() context manager from procutil This is a follow-up series for 23a00bc90a3c, "chgserver: do not send system() back to client if stdio redirected." The function is renamed using ui terms.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 26 Sep 2018 21:29:13 +0900
parents 4948b327d3b9
children cf8677cd7286
files mercurial/commandserver.py mercurial/ui.py mercurial/utils/procutil.py
diffstat 3 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commandserver.py	Thu Jan 10 21:29:24 2019 +0900
+++ b/mercurial/commandserver.py	Wed Sep 26 21:29:13 2018 +0900
@@ -399,7 +399,7 @@
         ui = self.ui
         # redirect stdio to null device so that broken extensions or in-process
         # hooks will never cause corruption of channel protocol.
-        with procutil.protectedstdio(ui.fin, ui.fout) as (fin, fout):
+        with ui.protectedfinout() as (fin, fout):
             sv = server(ui, self.repo, fin, fout)
             try:
                 return sv.serve()
--- a/mercurial/ui.py	Thu Jan 10 21:29:24 2019 +0900
+++ b/mercurial/ui.py	Wed Sep 26 21:29:13 2018 +0900
@@ -1080,6 +1080,15 @@
             return False
         return procutil.isatty(fh)
 
+    @contextlib.contextmanager
+    def protectedfinout(self):
+        """Run code block with protected standard streams"""
+        fin, fout = procutil.protectstdio(self._fin, self._fout)
+        try:
+            yield fin, fout
+        finally:
+            procutil.restorestdio(self._fin, self._fout, fin, fout)
+
     def disablepager(self):
         self._disablepager = True
 
--- a/mercurial/utils/procutil.py	Thu Jan 10 21:29:24 2019 +0900
+++ b/mercurial/utils/procutil.py	Wed Sep 26 21:29:13 2018 +0900
@@ -299,15 +299,6 @@
             os.dup2(f.fileno(), uif.fileno())
             f.close()
 
-@contextlib.contextmanager
-def protectedstdio(uin, uout):
-    """Run code block with protected standard streams"""
-    fin, fout = protectstdio(uin, uout)
-    try:
-        yield fin, fout
-    finally:
-        restorestdio(uin, uout, fin, fout)
-
 def shellenviron(environ=None):
     """return environ with optional override, useful for shelling out"""
     def py2shell(val):