diff options
author | Renaud Paquay <rpaquay@google.com> | 2016-11-01 11:23:38 -0700 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2017-05-29 19:29:30 +0900 |
commit | 2e7029116204cf2d6f516e4514091f0b492bc689 (patch) | |
tree | 0048544773ddc9d21706dfcc7307bdd3e2f6971f /subcmds/forall.py | |
parent | 35d22217a5ed2f8b5b9b183217923071ccfe7f37 (diff) | |
download | git-repo-2e7029116204cf2d6f516e4514091f0b492bc689.tar.gz |
Make "git command" and "forall" work on Windows
Python on Windows does not support non blocking file operations.
To workaround this issue, we instead use Threads and a Queue to
simulate non-blocking calls. This is happens only when running
with the native Windows version of Python, meaning Linux and Cygwin
are not affected by this change.
Change-Id: I4ce23827b096c5138f67a85c721f58a12279bb6f
Diffstat (limited to 'subcmds/forall.py')
-rw-r--r-- | subcmds/forall.py | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py index 07ee8d58..2c12c55f 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -15,17 +15,16 @@ | |||
15 | 15 | ||
16 | from __future__ import print_function | 16 | from __future__ import print_function |
17 | import errno | 17 | import errno |
18 | import fcntl | ||
19 | import multiprocessing | 18 | import multiprocessing |
20 | import re | 19 | import re |
21 | import os | 20 | import os |
22 | import select | ||
23 | import signal | 21 | import signal |
24 | import sys | 22 | import sys |
25 | import subprocess | 23 | import subprocess |
26 | 24 | ||
27 | from color import Coloring | 25 | from color import Coloring |
28 | from command import Command, MirrorSafeCommand | 26 | from command import Command, MirrorSafeCommand |
27 | import platform_utils | ||
29 | 28 | ||
30 | _CAN_COLOR = [ | 29 | _CAN_COLOR = [ |
31 | 'branch', | 30 | 'branch', |
@@ -344,35 +343,25 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config): | |||
344 | if opt.project_header: | 343 | if opt.project_header: |
345 | out = ForallColoring(config) | 344 | out = ForallColoring(config) |
346 | out.redirect(sys.stdout) | 345 | out.redirect(sys.stdout) |
347 | class sfd(object): | ||
348 | def __init__(self, fd, dest): | ||
349 | self.fd = fd | ||
350 | self.dest = dest | ||
351 | def fileno(self): | ||
352 | return self.fd.fileno() | ||
353 | |||
354 | empty = True | 346 | empty = True |
355 | errbuf = '' | 347 | errbuf = '' |
356 | 348 | ||
357 | p.stdin.close() | 349 | p.stdin.close() |
358 | s_in = [sfd(p.stdout, sys.stdout), | 350 | s_in = platform_utils.FileDescriptorStreams.create() |
359 | sfd(p.stderr, sys.stderr)] | 351 | s_in.add(p.stdout, sys.stdout, 'stdout') |
360 | 352 | s_in.add(p.stderr, sys.stderr, 'stderr') | |
361 | for s in s_in: | ||
362 | flags = fcntl.fcntl(s.fd, fcntl.F_GETFL) | ||
363 | fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) | ||
364 | 353 | ||
365 | while s_in: | 354 | while not s_in.is_done: |
366 | in_ready, _out_ready, _err_ready = select.select(s_in, [], []) | 355 | in_ready = s_in.select() |
367 | for s in in_ready: | 356 | for s in in_ready: |
368 | buf = s.fd.read(4096) | 357 | buf = s.read() |
369 | if not buf: | 358 | if not buf: |
370 | s.fd.close() | 359 | s.close() |
371 | s_in.remove(s) | 360 | s_in.remove(s) |
372 | continue | 361 | continue |
373 | 362 | ||
374 | if not opt.verbose: | 363 | if not opt.verbose: |
375 | if s.fd != p.stdout: | 364 | if s.std_name == 'stderr': |
376 | errbuf += buf | 365 | errbuf += buf |
377 | continue | 366 | continue |
378 | 367 | ||