# HG changeset patch # User Thomas De Schampheleire # Date 1321428876 -3600 # Node ID 8b011ededfb2abe73f99996bd4ef4bc0b74dd78b # Parent 6cae68a361ed49c086659fce9f87eec135805958 hook: flush stdout before redirecting to stderr When hook output redirection is enabled (e.g. when cloning over ssh), hook output on stdout is redirected to stderr, to prevent the repository data on stdout from being corrupted. In certain cases, the redirection could cause part of the repository data to end up on stderr as well. In case of a clone, this causes: "abort: consistency error in delta!" This was seen with a clone over ssh, an outgoing hook present (any non-python type, e.g. 'pwd'), on certain repositories only, probably depending on the distribution of the sent data) This patch updates the hook redirection code to flush stdout before redirecting, removing the problem. diff -r 6cae68a361ed -r 8b011ededfb2 mercurial/hook.py --- a/mercurial/hook.py Wed Nov 16 12:53:10 2011 +0100 +++ b/mercurial/hook.py Wed Nov 16 08:34:36 2011 +0100 @@ -139,6 +139,7 @@ stderrno = sys.__stderr__.fileno() # temporarily redirect stdout to stderr, if possible if stdoutno >= 0 and stderrno >= 0: + sys.__stdout__.flush() oldstdout = os.dup(stdoutno) os.dup2(stderrno, stdoutno) except AttributeError: