--- a/mercurial/chgserver.py Tue Sep 25 08:53:20 2018 -0700
+++ b/mercurial/chgserver.py Wed Sep 26 08:46:56 2018 -0700
@@ -198,13 +198,15 @@
self._csystem = csystem
def _runsystem(self, cmd, environ, cwd, out):
- # fallback to the original system method if the output needs to be
- # captured (to self._buffers), or the output stream is not stdout
- # (e.g. stderr, cStringIO), because the chg client is not aware of
- # these situations and will behave differently (write to stdout).
+ # 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)
--- a/mercurial/ui.py Tue Sep 25 08:53:20 2018 -0700
+++ b/mercurial/ui.py Wed Sep 26 08:46:56 2018 -0700
@@ -234,6 +234,7 @@
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
@@ -258,6 +259,7 @@
self.fout = procutil.stdout
self.ferr = procutil.stderr
self.fin = procutil.stdin
+ self._finoutredirected = False
self.pageractive = False
self._disablepager = False
self._tweaked = False
--- a/mercurial/utils/procutil.py Tue Sep 25 08:53:20 2018 -0700
+++ b/mercurial/utils/procutil.py Wed Sep 26 08:46:56 2018 -0700
@@ -278,13 +278,13 @@
"""
uout.flush()
fin, fout = uin, uout
- if uin is stdin:
+ if _testfileno(uin, stdin):
newfd = os.dup(uin.fileno())
nullfd = os.open(os.devnull, os.O_RDONLY)
os.dup2(nullfd, uin.fileno())
os.close(nullfd)
fin = os.fdopen(newfd, r'rb')
- if uout is stdout:
+ if _testfileno(uout, stdout):
newfd = os.dup(uout.fileno())
os.dup2(stderr.fileno(), uout.fileno())
fout = os.fdopen(newfd, r'wb')
--- a/mercurial/wireprotoserver.py Tue Sep 25 08:53:20 2018 -0700
+++ b/mercurial/wireprotoserver.py Wed Sep 26 08:46:56 2018 -0700
@@ -783,6 +783,8 @@
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:
--- a/tests/test-ssh.t Tue Sep 25 08:53:20 2018 -0700
+++ b/tests/test-ssh.t Wed Sep 26 08:46:56 2018 -0700
@@ -313,6 +313,26 @@
summary: z
+#if chg
+
+try again with remote chg, which should succeed as well
+
+ $ hg rollback -R ../remote
+ repository tip rolled back to revision 4 (undo serve)
+
+ $ hg push --config ui.remotecmd=chg
+ pushing to ssh://user@dummy/remote
+ searching for changes
+ remote has heads on branch 'default' that are not known locally: 6c0482d977a3
+ remote: adding changesets
+ remote: adding manifests
+ remote: adding file changes
+ remote: added 1 changesets with 1 changes to 1 files
+ remote: KABOOM
+ remote: KABOOM IN PROCESS
+
+#endif
+
clone bookmarks
$ hg -R ../remote bookmark test
@@ -554,6 +574,8 @@
Got arguments 1:user@dummy 2:hg -R remote serve --stdio
Got arguments 1:user@dummy 2:hg -R remote serve --stdio
changegroup-in-remote hook: HG_BUNDLE2=1 HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=1383141674ec756a6056f6a9097618482fe0f4a6 HG_NODE_LAST=1383141674ec756a6056f6a9097618482fe0f4a6 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:ssh:$LOCALIP
+ Got arguments 1:user@dummy 2:chg -R remote serve --stdio (chg !)
+ changegroup-in-remote hook: HG_BUNDLE2=1 HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=1383141674ec756a6056f6a9097618482fe0f4a6 HG_NODE_LAST=1383141674ec756a6056f6a9097618482fe0f4a6 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:ssh:$LOCALIP (chg !)
Got arguments 1:user@dummy 2:hg -R remote serve --stdio
Got arguments 1:user@dummy 2:hg init 'a repo'
Got arguments 1:user@dummy 2:hg -R 'a repo' serve --stdio