Skip to content

Commit

Permalink
git-remote-testpy: don't do unbuffered text I/O
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
John Keeping authored and Junio C Hamano committed Jan 25, 2013
1 parent 0846b0c commit d04c94a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions git-remote-testpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def do_import(repo, args):
refs = [ref]

while True:
line = sys.stdin.readline()
line = sys.stdin.readline().decode()
if line == '\n':
break
if not line.startswith('import '):
Expand Down Expand Up @@ -225,7 +225,7 @@ def read_one_line(repo):

line = sys.stdin.readline()

cmdline = line
cmdline = line.decode()

if not cmdline:
warn("Unexpected EOF")
Expand Down Expand Up @@ -277,7 +277,11 @@ def main(args):

more = True

sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
# Use binary mode since Python 3 does not permit unbuffered I/O in text
# mode. Unbuffered I/O is required to avoid data that should be going
# to git-fast-import after an "export" command getting caught in our
# stdin buffer instead.
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
while (more):
more = read_one_line(repo)

Expand Down

0 comments on commit d04c94a

Please sign in to comment.