diff options
Diffstat (limited to 'git_command.py')
-rw-r--r-- | git_command.py | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/git_command.py b/git_command.py index 9f7d2930..b1e9e172 100644 --- a/git_command.py +++ b/git_command.py | |||
@@ -14,14 +14,14 @@ | |||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | from __future__ import print_function | 16 | from __future__ import print_function |
17 | import fcntl | ||
18 | import os | 17 | import os |
19 | import select | ||
20 | import sys | 18 | import sys |
21 | import subprocess | 19 | import subprocess |
22 | import tempfile | 20 | import tempfile |
23 | from signal import SIGTERM | 21 | from signal import SIGTERM |
22 | |||
24 | from error import GitError | 23 | from error import GitError |
24 | import platform_utils | ||
25 | from trace import REPO_TRACE, IsTrace, Trace | 25 | from trace import REPO_TRACE, IsTrace, Trace |
26 | from wrapper import Wrapper | 26 | from wrapper import Wrapper |
27 | 27 | ||
@@ -78,16 +78,6 @@ def terminate_ssh_clients(): | |||
78 | 78 | ||
79 | _git_version = None | 79 | _git_version = None |
80 | 80 | ||
81 | class _sfd(object): | ||
82 | """select file descriptor class""" | ||
83 | def __init__(self, fd, dest, std_name): | ||
84 | assert std_name in ('stdout', 'stderr') | ||
85 | self.fd = fd | ||
86 | self.dest = dest | ||
87 | self.std_name = std_name | ||
88 | def fileno(self): | ||
89 | return self.fd.fileno() | ||
90 | |||
91 | class _GitCall(object): | 81 | class _GitCall(object): |
92 | def version(self): | 82 | def version(self): |
93 | p = GitCommand(None, ['--version'], capture_stdout=True) | 83 | p = GitCommand(None, ['--version'], capture_stdout=True) |
@@ -162,6 +152,7 @@ class GitCommand(object): | |||
162 | if ssh_proxy: | 152 | if ssh_proxy: |
163 | _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) | 153 | _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) |
164 | _setenv(env, 'GIT_SSH', _ssh_proxy()) | 154 | _setenv(env, 'GIT_SSH', _ssh_proxy()) |
155 | _setenv(env, 'GIT_SSH_VARIANT', 'ssh') | ||
165 | if 'http_proxy' in env and 'darwin' == sys.platform: | 156 | if 'http_proxy' in env and 'darwin' == sys.platform: |
166 | s = "'http.proxy=%s'" % (env['http_proxy'],) | 157 | s = "'http.proxy=%s'" % (env['http_proxy'],) |
167 | p = env.get('GIT_CONFIG_PARAMETERS') | 158 | p = env.get('GIT_CONFIG_PARAMETERS') |
@@ -253,19 +244,16 @@ class GitCommand(object): | |||
253 | 244 | ||
254 | def _CaptureOutput(self): | 245 | def _CaptureOutput(self): |
255 | p = self.process | 246 | p = self.process |
256 | s_in = [_sfd(p.stdout, sys.stdout, 'stdout'), | 247 | s_in = platform_utils.FileDescriptorStreams.create() |
257 | _sfd(p.stderr, sys.stderr, 'stderr')] | 248 | s_in.add(p.stdout, sys.stdout, 'stdout') |
249 | s_in.add(p.stderr, sys.stderr, 'stderr') | ||
258 | self.stdout = '' | 250 | self.stdout = '' |
259 | self.stderr = '' | 251 | self.stderr = '' |
260 | 252 | ||
261 | for s in s_in: | 253 | while not s_in.is_done: |
262 | flags = fcntl.fcntl(s.fd, fcntl.F_GETFL) | 254 | in_ready = s_in.select() |
263 | fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) | ||
264 | |||
265 | while s_in: | ||
266 | in_ready, _, _ = select.select(s_in, [], []) | ||
267 | for s in in_ready: | 255 | for s in in_ready: |
268 | buf = s.fd.read(4096) | 256 | buf = s.read() |
269 | if not buf: | 257 | if not buf: |
270 | s_in.remove(s) | 258 | s_in.remove(s) |
271 | continue | 259 | continue |