@@ -69,6 +69,10 @@ def _bchr(c):
69
69
# Documentation
70
70
## @{
71
71
72
+ def _drop_output_handler (line ):
73
+ pass
74
+
75
+
72
76
def handle_process_output (process , stdout_handler , stderr_handler , finalizer ):
73
77
"""Registers for notifications to lean that process output is ready to read, and dispatches lines to
74
78
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):
79
83
:param stdout_handler: f(stdout_line_string), or None
80
84
:param stderr_hanlder: f(stderr_line_string), or None
81
85
: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
+
82
93
fdmap = {process .stdout .fileno (): (stdout_handler , [b'' ]),
83
94
process .stderr .fileno (): (stderr_handler , [b'' ])}
84
95
@@ -119,6 +130,7 @@ def _dispatch_single_line(line, handler):
119
130
# end single line helper
120
131
121
132
def _dispatch_lines (fno , handler , buf_list ):
133
+ log .debug ('fno=%d, handler=%r, buf_list=%r' % (fno , handler , buf_list ))
122
134
lc = 0
123
135
for line in _read_lines_from_fno (fno , buf_list ):
124
136
_dispatch_single_line (line , handler )
@@ -307,22 +319,35 @@ def __del__(self):
307
319
def __getattr__ (self , attr ):
308
320
return getattr (self .proc , attr )
309
321
310
- def wait (self , stderr = None ):
322
+ def wait (self , stderr = b'' ):
311
323
"""Wait for the process and return its status code.
312
324
313
325
:param stderr: Previously read value of stderr, in case stderr is already closed.
314
326
:warn: may deadlock if output or error pipes are used and not handled separately.
315
327
: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
+
316
337
status = self .proc .wait ()
317
338
318
339
def read_all_from_possibly_closed_stream (stream ):
319
340
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
321
345
except ValueError :
322
- return stderr or ''
346
+ return stderr or b ''
323
347
324
348
if status != 0 :
325
349
errstr = read_all_from_possibly_closed_stream (self .proc .stderr )
350
+ log .debug ('AutoInterrupt wait stderr: %r' % (errstr ,))
326
351
raise GitCommandError (self .args , status , errstr )
327
352
# END status handling
328
353
return status
@@ -609,7 +634,7 @@ def execute(self, command,
609
634
bufsize = - 1 ,
610
635
stdin = istream ,
611
636
stderr = PIPE ,
612
- stdout = PIPE if with_stdout else open ( os . devnull , 'wb' ) ,
637
+ stdout = PIPE ,
613
638
shell = self .USE_SHELL ,
614
639
close_fds = (os .name == 'posix' ), # unsupported on windows
615
640
universal_newlines = universal_newlines ,
0 commit comments