@@ -69,6 +69,10 @@ def _bchr(c):
6969# Documentation
7070## @{
7171
72+ def _drop_output_handler (line ):
73+ pass
74+
75+
7276def handle_process_output (process , stdout_handler , stderr_handler , finalizer ):
7377 """Registers for notifications to lean that process output is ready to read, and dispatches lines to
7478 the respective line handlers. We are able to handle carriage returns in case progress is sent by that
@@ -79,6 +83,13 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer):
7983 :param stdout_handler: f(stdout_line_string), or None
8084 :param stderr_hanlder: f(stderr_line_string), or None
8185 :param finalizer: f(proc) - wait for proc to finish"""
86+
87+ log .debug ('handle_process_output( process=%r, stdout_handler=%r, stderr_handler=%r, finalizer=%r'
88+ % (process , stdout_handler , stderr_handler , finalizer ))
89+
90+ if stdout_handler is None :
91+ stdout_handler = _drop_output_handler
92+
8293 fdmap = {process .stdout .fileno (): (stdout_handler , [b'' ]),
8394 process .stderr .fileno (): (stderr_handler , [b'' ])}
8495
@@ -119,6 +130,7 @@ def _dispatch_single_line(line, handler):
119130 # end single line helper
120131
121132 def _dispatch_lines (fno , handler , buf_list ):
133+ log .debug ('fno=%d, handler=%r, buf_list=%r' % (fno , handler , buf_list ))
122134 lc = 0
123135 for line in _read_lines_from_fno (fno , buf_list ):
124136 _dispatch_single_line (line , handler )
@@ -307,22 +319,35 @@ def __del__(self):
307319 def __getattr__ (self , attr ):
308320 return getattr (self .proc , attr )
309321
310- def wait (self , stderr = None ):
322+ def wait (self , stderr = b'' ):
311323 """Wait for the process and return its status code.
312324
313325 :param stderr: Previously read value of stderr, in case stderr is already closed.
314326 :warn: may deadlock if output or error pipes are used and not handled separately.
315327 :raise GitCommandError: if the return status is not 0"""
328+
329+ # stderr must be a bytes object as it will
330+ # combined with more data from the process and
331+ # decoded by the caller
332+ if stderr is None :
333+ stderr = b''
334+ elif type (stderr ) == unicode :
335+ stderr = stderr .encode (defenc )
336+
316337 status = self .proc .wait ()
317338
318339 def read_all_from_possibly_closed_stream (stream ):
319340 try :
320- return stream .read ()
341+ last_stderr = stream .read ()
342+ if type (last_stderr ) == unicode :
343+ last_stderr = last_stderr .encode (defenc )
344+ return stderr + last_stderr
321345 except ValueError :
322- return stderr or ''
346+ return stderr or b ''
323347
324348 if status != 0 :
325349 errstr = read_all_from_possibly_closed_stream (self .proc .stderr )
350+ log .debug ('AutoInterrupt wait stderr: %r' % (errstr ,))
326351 raise GitCommandError (self .args , status , errstr )
327352 # END status handling
328353 return status
@@ -609,7 +634,7 @@ def execute(self, command,
609634 bufsize = - 1 ,
610635 stdin = istream ,
611636 stderr = PIPE ,
612- stdout = PIPE if with_stdout else open ( os . devnull , 'wb' ) ,
637+ stdout = PIPE ,
613638 shell = self .USE_SHELL ,
614639 close_fds = (os .name == 'posix' ), # unsupported on windows
615640 universal_newlines = universal_newlines ,
0 commit comments