Skip to content

Commit d04c94a

Browse files
johnkeepinggitster
authored andcommitted
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>
1 parent 0846b0c commit d04c94a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

git-remote-testpy.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def do_import(repo, args):
154154
refs = [ref]
155155

156156
while True:
157-
line = sys.stdin.readline()
157+
line = sys.stdin.readline().decode()
158158
if line == '\n':
159159
break
160160
if not line.startswith('import '):
@@ -225,7 +225,7 @@ def read_one_line(repo):
225225

226226
line = sys.stdin.readline()
227227

228-
cmdline = line
228+
cmdline = line.decode()
229229

230230
if not cmdline:
231231
warn("Unexpected EOF")
@@ -277,7 +277,11 @@ def main(args):
277277

278278
more = True
279279

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)
281285
while (more):
282286
more = read_one_line(repo)
283287

0 commit comments

Comments
 (0)