summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--git_command.py40
1 files changed, 7 insertions, 33 deletions
diff --git a/git_command.py b/git_command.py
index 6cb6e0c3..8bd4e67e 100644
--- a/git_command.py
+++ b/git_command.py
@@ -259,9 +259,6 @@ class GitCommand(object):
259 gitdir=None): 259 gitdir=None):
260 env = self._GetBasicEnv() 260 env = self._GetBasicEnv()
261 261
262 # If we are not capturing std* then need to print it.
263 self.tee = {'stdout': not capture_stdout, 'stderr': not capture_stderr}
264
265 if disable_editor: 262 if disable_editor:
266 env['GIT_EDITOR'] = ':' 263 env['GIT_EDITOR'] = ':'
267 if ssh_proxy: 264 if ssh_proxy:
@@ -299,8 +296,9 @@ class GitCommand(object):
299 command.extend(cmdv[1:]) 296 command.extend(cmdv[1:])
300 297
301 stdin = subprocess.PIPE if input else None 298 stdin = subprocess.PIPE if input else None
302 stdout = subprocess.PIPE 299 stdout = subprocess.PIPE if capture_stdout else None
303 stderr = subprocess.STDOUT if merge_output else subprocess.PIPE 300 stderr = (subprocess.STDOUT if merge_output else
301 (subprocess.PIPE if capture_stderr else None))
304 302
305 if IsTrace(): 303 if IsTrace():
306 global LAST_CWD 304 global LAST_CWD
@@ -336,6 +334,8 @@ class GitCommand(object):
336 p = subprocess.Popen(command, 334 p = subprocess.Popen(command,
337 cwd=cwd, 335 cwd=cwd,
338 env=env, 336 env=env,
337 encoding='utf-8',
338 errors='backslashreplace',
339 stdin=stdin, 339 stdin=stdin,
340 stdout=stdout, 340 stdout=stdout,
341 stderr=stderr) 341 stderr=stderr)
@@ -353,9 +353,10 @@ class GitCommand(object):
353 p.stdin.close() 353 p.stdin.close()
354 354
355 try: 355 try:
356 self.rc = self._CaptureOutput() 356 self.stdout, self.stderr = p.communicate()
357 finally: 357 finally:
358 _remove_ssh_client(p) 358 _remove_ssh_client(p)
359 self.rc = p.wait()
359 360
360 @staticmethod 361 @staticmethod
361 def _GetBasicEnv(): 362 def _GetBasicEnv():
@@ -376,30 +377,3 @@ class GitCommand(object):
376 377
377 def Wait(self): 378 def Wait(self):
378 return self.rc 379 return self.rc
379
380 def _CaptureOutput(self):
381 p = self.process
382 s_in = platform_utils.FileDescriptorStreams.create()
383 s_in.add(p.stdout, sys.stdout, 'stdout')
384 if p.stderr is not None:
385 s_in.add(p.stderr, sys.stderr, 'stderr')
386 self.stdout = ''
387 self.stderr = ''
388
389 while not s_in.is_done:
390 in_ready = s_in.select()
391 for s in in_ready:
392 buf = s.read()
393 if not buf:
394 s_in.remove(s)
395 continue
396 if not hasattr(buf, 'encode'):
397 buf = buf.decode('utf-8', 'backslashreplace')
398 if s.std_name == 'stdout':
399 self.stdout += buf
400 else:
401 self.stderr += buf
402 if self.tee[s.std_name]:
403 s.dest.write(buf)
404 s.dest.flush()
405 return p.wait()