[PATCH] hook: flush stdout before redirecting to stderr

Thomas De Schampheleire patrickdepinguin+mercurial at gmail.com
Wed Nov 16 01:51:42 CST 2011


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1321428876 -3600
# Node ID a799e2c5b264d4aa88e26f9a5b6c20ca8134b4df
# Parent  25ea33fe7e5cb4f14dd919f50fbdbee376b6bf78
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 --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -139,6 +139,7 @@ def hook(ui, repo, name, throw=False, **
             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:




More information about the Mercurial-devel mailing list