[PATCH 4 of 4 STABLE] chgserver: do not send system() back to client if stdio redirected (issue5992)
Yuya Nishihara
yuya at tcha.org
Wed Sep 26 09:59:16 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1537964654 -32400
# Wed Sep 26 21:24:14 2018 +0900
# Branch stable
# Node ID 201b773dc53b0dfe2d6690858191352e62412fbc
# Parent 56a416fce073de56738286c469bf0931ebbddab2
chgserver: do not send system() back to client if stdio redirected (issue5992)
As the chg client doesn't know server-side stdio redirection, the server
shouldn't upcall on "runsystem" request if the stdio streams are redirected.
This patch teaches ui to remember the redirection flag, which is updated by
the caller right now. Future patches (for default) will add ui methods to
manage this flag internally.
diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -200,11 +200,13 @@ def _newchgui(srcui, csystem, attachio):
def _runsystem(self, cmd, environ, cwd, out):
# fallback to the original system method if
# a. the output stream is not stdout (e.g. stderr, cStringIO),
+ # b. or stdout is redirected by protectstdio(),
# because the chg client is not aware of these situations and
# will behave differently (i.e. write to stdout).
if (out is not self.fout
or not util.safehasattr(self.fout, 'fileno')
- or self.fout.fileno() != procutil.stdout.fileno()):
+ or self.fout.fileno() != procutil.stdout.fileno()
+ or self._finoutredirected):
return procutil.system(cmd, environ=environ, cwd=cwd, out=out)
self.flush()
return self._csystem(cmd, procutil.shellenviron(environ), cwd)
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -231,6 +231,7 @@ class ui(object):
self.fout = src.fout
self.ferr = src.ferr
self.fin = src.fin
+ self._finoutredirected = src._finoutredirected
self.pageractive = src.pageractive
self._disablepager = src._disablepager
self._tweaked = src._tweaked
@@ -255,6 +256,7 @@ class ui(object):
self.fout = procutil.stdout
self.ferr = procutil.stderr
self.fin = procutil.stdin
+ self._finoutredirected = False
self.pageractive = False
self._disablepager = False
self._tweaked = False
diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -785,6 +785,8 @@ class sshserver(object):
self._ui = ui
self._repo = repo
self._fin, self._fout = procutil.protectstdio(ui.fin, ui.fout)
+ # TODO: manage the redirection flag internally by ui
+ ui._finoutredirected = (self._fin, self._fout) != (ui.fin, ui.fout)
# Log write I/O to stdout and stderr if configured.
if logfh:
diff --git a/tests/test-ssh.t b/tests/test-ssh.t
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -332,8 +332,8 @@ try again with remote chg, which should
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
- abort: not a Mercurial bundle
- [255]
+ remote: KABOOM
+ remote: KABOOM IN PROCESS
#endif
More information about the Mercurial-devel
mailing list