diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py --- a/mercurial/chgserver.py +++ b/mercurial/chgserver.py @@ -198,13 +198,15 @@ def _newchgui(srcui, csystem, attachio): 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) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -234,6 +234,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 @@ -258,6 +259,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/utils/procutil.py b/mercurial/utils/procutil.py --- a/mercurial/utils/procutil.py +++ b/mercurial/utils/procutil.py @@ -278,13 +278,13 @@ def protectstdio(uin, uout): """ 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') diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -783,6 +783,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 @@ -313,6 +313,26 @@ push should succeed even though it has a 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 @@ debug output 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