summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Harding <dharding@gmail.com>2012-09-30 07:24:16 +0100
committerDaniel Harding <dharding@gmail.com>2012-09-30 11:10:48 +0100
commit7eaba68bc2497cb5adbf3e8a01ad3f3ac657cf7b (patch)
tree677cefd4534ff65d63e6cc55bad87609dea93903
parente63f780004ac72056aa864fd7e6ead5cd01e2c9f (diff)
downloadhg-fast-export-7eaba68bc2497cb5adbf3e8a01ad3f3ac657cf7b.tar.gz
Make hg-fast-export (actually) work on Windows
Because on Windows sys.stdout is initially in text mode, any LF characters written to it will be transformed to CRLF, which causes git to blow up. This change uses Windows platform-specific code to change sys.stdout to binary mode.
-rwxr-xr-xhg-fast-export.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/hg-fast-export.py b/hg-fast-export.py
index 0e0fa87..1fe2999 100755
--- a/hg-fast-export.py
+++ b/hg-fast-export.py
@@ -11,6 +11,14 @@ import re
import sys
import os
+if sys.platform == "win32":
+ # On Windows, sys.stdout is initially opened in text mode, which means that
+ # when a LF (\n) character is written to sys.stdout, it will be converted
+ # into CRLF (\r\n). That makes git blow up, so use this platform-specific
+ # code to change the mode of sys.stdout to binary.
+ import msvcrt
+ msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+
# silly regex to catch Signed-off-by lines in log message
sob_re=re.compile('^Signed-[Oo]ff-[Bb]y: (.+)$')
# insert 'checkpoint' command after this many commits or none at all if 0