comparison mercurial/hook.py @ 15512:8b011ededfb2 stable

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.
author Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
date Wed, 16 Nov 2011 08:34:36 +0100
parents f6a737357195
children 30c34fde40cc
comparison
equal deleted inserted replaced
15511:6cae68a361ed 15512:8b011ededfb2
137 try: 137 try:
138 stdoutno = sys.__stdout__.fileno() 138 stdoutno = sys.__stdout__.fileno()
139 stderrno = sys.__stderr__.fileno() 139 stderrno = sys.__stderr__.fileno()
140 # temporarily redirect stdout to stderr, if possible 140 # temporarily redirect stdout to stderr, if possible
141 if stdoutno >= 0 and stderrno >= 0: 141 if stdoutno >= 0 and stderrno >= 0:
142 sys.__stdout__.flush()
142 oldstdout = os.dup(stdoutno) 143 oldstdout = os.dup(stdoutno)
143 os.dup2(stderrno, stdoutno) 144 os.dup2(stderrno, stdoutno)
144 except AttributeError: 145 except AttributeError:
145 # __stdout/err__ doesn't have fileno(), it's not a real file 146 # __stdout/err__ doesn't have fileno(), it's not a real file
146 pass 147 pass