Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hook.py @ 14889:a59058fd074a stable
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
We need to make sure that python hooks I/O goes through the ui descriptors so
it doesn't mess the command server protocol.
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 19:06:59 +0300 |
parents | ac70f8d5987c |
children | 58f97dcbd550 |
line wrap: on
line diff
--- a/mercurial/hook.py Fri Jul 15 20:07:19 2011 +0200 +++ b/mercurial/hook.py Sat Jul 09 19:06:59 2011 +0300 @@ -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)