git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 7/8] git-remote-testpy: don't do unbuffered text I/O

From
John Keeping <john@keeping.me.uk>
Date
Jan 20, 2013, 13:15 UTC
Message-ID
<c73b8e6e762bbf19e840994e4ff6e99de465051c.1358686905.git.john@keeping.me.uk>
In-Reply-To
<cover.1358686905.git.john@keeping.me.uk>

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>
---
 git-remote-testpy.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/git-remote-testpy.py b/git-remote-testpy.py
index 197b7be..5dbf1cc 100644
--- a/git-remote-testpy.py
+++ b/git-remote-testpy.py
@@ -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 '):
@@ -225,7 +225,7 @@ def read_one_line(repo):
 
     line = sys.stdin.readline()
 
-    cmdline = line
+    cmdline = line.decode()
 
     if not cmdline:
         warn("Unexpected EOF")
@@ -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)
 
-- 
1.8.1.353.gc992d5a.dirty
Previous: Junio C HamanoNext: John Keeping
Message 37 of 38 in “Python 3 support for git_remote_helpers”
  1. 0/8 Python 3 support for git_remote_helpersJohn Keeping, Jan 20, 2013
  2. 1/8 git_remote_helpers: Allow building with Python 3John Keeping, Jan 20, 2013
  3. Sverre RabbelierJan 23, 2013
  4. 2/8 git_remote_helpers: fix input when running under Python 3John Keeping, Jan 20, 2013
  5. Sverre RabbelierJan 23, 2013
  6. John KeepingJan 23, 2013
  7. Sverre RabbelierJan 23, 2013
  8. Junio C HamanoJan 23, 2013
  9. Brandon CaseyJan 25, 2013
  10. Erik Faye-LundFeb 5, 2013
  11. 3/8 git_remote_helpers: Force rebuild if python version changesJohn Keeping, Jan 20, 2013
  12. Sverre RabbelierJan 23, 2013
  13. 4/8 git_remote_helpers: Use 2to3 if building with Python 3John Keeping, Jan 20, 2013
  14. 5/8 svn-fe: allow svnrdump_sim.py to run with Python 3John Keeping, Jan 20, 2013
  15. 6/8 git-remote-testpy: hash bytes explicitlyJohn Keeping, Jan 20, 2013
  16. John KeepingJan 26, 2013
  17. Junio C HamanoJan 26, 2013
  18. git-remote-testpy: fix patch hashing on Python 3John Keeping, Jan 26, 2013
  19. Michael HaggertyJan 27, 2013
  20. Junio C HamanoJan 27, 2013
  21. John KeepingJan 27, 2013
  22. Sverre RabbelierJan 27, 2013
  23. Michael HaggertyJan 27, 2013
  24. John KeepingJan 27, 2013
  25. git-remote-testpy: fix patch hashing on Python 3John Keeping, Jan 27, 2013
  26. Junio C HamanoJan 27, 2013
  27. John KeepingJan 27, 2013
  28. Junio C HamanoJan 27, 2013
  29. John KeepingJan 27, 2013
  30. Junio C HamanoJan 27, 2013
  31. Junio C HamanoJan 27, 2013
  32. John KeepingJan 27, 2013
  33. Junio C HamanoJan 27, 2013
  34. Michael HaggertyJan 28, 2013
  35. fixup! git-remote-testpy: fix path hashing on Python 3John Keeping, Jan 28, 2013
  36. Junio C HamanoJan 28, 2013
  37. 7/8 git-remote-testpy: don't do unbuffered text I/OJohn Keeping, Jan 20, 2013
  38. 8/8 git-remote-testpy: call print as a functionJohn Keeping, Jan 20, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.