git-remote-testpy: don't do unbuffered text I/O
Python 3 forbids unbuffered I/O in text mode. Change the reading of stdin in git-remote-testpy so that we read the lines as bytes and then decode them a line at a time. This allows us to keep the I/O unbuffered in order to avoid reintroducing the bug fixed by commit 7fb8e16 (git-remote-testgit: fix race when spawning fast-import). Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
John Keeping committed
Jan 20, 2013 at 13:15 UTC
d04c94a2ea21cb218b43be192d8569c0e669d080
1 file changed
+7
-3
git-remote-testpy.py
+7
-3
@@ -154,7 +154,7 @@ def do_import(repo, args):
154
refs = [ref]
155
156
while True:
157
- line = sys.stdin.readline()
157
+ line = sys.stdin.readline().decode()
158
if line == '\n':
159
break
160
if not line.startswith('import '):
@@ -225,7 +225,7 @@ def read_one_line(repo):
225
226
line = sys.stdin.readline()
227
228
- cmdline = line
228
+ cmdline = line.decode()
229
230
if not cmdline:
231
warn("Unexpected EOF")
@@ -277,7 +277,11 @@ def main(args):
277
278
more = True
279
280
- sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
280
+ # Use binary mode since Python 3 does not permit unbuffered I/O in text
281
+ # mode. Unbuffered I/O is required to avoid data that should be going
282
+ # to git-fast-import after an "export" command getting caught in our
283
+ # stdin buffer instead.
284
+ sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
285
while (more):
286
more = read_one_line(repo)
287