Mercurial > hg-stable
changeset 14896:1a841d2b4bb1
merge with stable
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 19 Jul 2011 14:19:04 -0500 |
parents | a35d6f822e3e (current diff) d2d592718e90 (diff) |
children | 6d1d0b9c4ecc |
files | |
diffstat | 4 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hook.py Sun Jul 17 00:36:43 2011 +0200 +++ b/mercurial/hook.py Tue Jul 19 14:19:04 2011 -0500 @@ -65,6 +65,12 @@ '("%s" is not callable)') % (hname, funcname)) try: + # redirect IO descriptors the the ui descriptors so hooks that write + # directly to these don't mess the command protocol when running through + # the command server + old = sys.stdout, sys.stderr, sys.stdin + sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin + r = obj(ui=ui, repo=repo, hooktype=name, **args) except KeyboardInterrupt: raise @@ -79,6 +85,8 @@ raise ui.traceback() return True + finally: + sys.stdout, sys.stderr, sys.stdin = old if r: if throw: raise util.Abort(_('%s hook failed') % hname)
--- a/mercurial/windows.py Sun Jul 17 00:36:43 2011 +0200 +++ b/mercurial/windows.py Tue Jul 19 14:19:04 2011 -0500 @@ -62,7 +62,7 @@ self.close() raise IOError(errno.EPIPE, 'Broken pipe') -sys.stdout = winstdout(sys.stdout) +sys.__stdout__ = sys.stdout = winstdout(sys.stdout) def _is_win_9x(): '''return true if run on windows 95, 98 or me.'''
--- a/tests/test-commandserver.py Sun Jul 17 00:36:43 2011 +0200 +++ b/tests/test-commandserver.py Tue Jul 19 14:19:04 2011 -0500 @@ -144,6 +144,16 @@ runcommand(server, ['-R', 'foo', 'showconfig']) shutil.rmtree('foo') +def hook(**args): + print 'hook talking' + print 'now try to read something: %r' % sys.stdin.read() + +def hookoutput(server): + readchannel(server) + runcommand(server, ['--config', + 'hooks.pre-identify=python:test-commandserver.hook', 'id'], + input=cStringIO.StringIO('some input')) + if __name__ == '__main__': os.system('hg init') @@ -158,3 +168,4 @@ hgrc.write('[ui]\nfoo=bar\n') hgrc.close() check(localhgrc) + check(hookoutput)