diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2016-06-13 10:07:40 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2016-06-13 10:07:40 +0200 |
commit | 15ee5a505b43741cdb7c79f41ebfa3d881910a6c (patch) | |
tree | 53d38efc5e78a7114f0727192cfc156d992b91c3 /git/cmd.py | |
parent | da86442f6a7bf1263fb5aafdaf904ed2f7db839f (diff) | |
download | gitpython-15ee5a505b43741cdb7c79f41ebfa3d881910a6c.tar.gz |
fix(misc): various cleanup
Just went through all changes and adjusted them to the best of my
abilities. As there are no tests to claim otherwise, I believe
this is correct enough.
However, it becomes evident that it's no longer possible to just
make changes without backing them with a respective test.
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 31 |
1 files changed, 6 insertions, 25 deletions
@@ -36,6 +36,7 @@ from .exc import ( from git.compat import ( string_types, defenc, + force_bytes, PY3, bchr, # just to satisfy flake8 on py3 @@ -69,10 +70,6 @@ else: # Documentation ## @{ -def _drop_output_handler(line): - pass - - def handle_process_output(process, stdout_handler, stderr_handler, finalizer): """Registers for notifications to lean that process output is ready to read, and dispatches lines to the respective line handlers. We are able to handle carriage returns in case progress is sent by that @@ -83,13 +80,6 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): :param stdout_handler: f(stdout_line_string), or None :param stderr_hanlder: f(stderr_line_string), or None :param finalizer: f(proc) - wait for proc to finish""" - - log.debug('handle_process_output( process=%r, stdout_handler=%r, stderr_handler=%r, finalizer=%r' - % (process, stdout_handler, stderr_handler, finalizer)) - - if stdout_handler is None: - stdout_handler = _drop_output_handler - fdmap = {process.stdout.fileno(): (stdout_handler, [b'']), process.stderr.fileno(): (stderr_handler, [b''])} @@ -130,7 +120,6 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): # end single line helper def _dispatch_lines(fno, handler, buf_list): - log.debug('fno=%d, handler=%r, buf_list=%r' % (fno, handler, buf_list)) lc = 0 for line in _read_lines_from_fno(fno, buf_list): _dispatch_single_line(line, handler) @@ -325,23 +314,15 @@ class Git(LazyMixin): :param stderr: Previously read value of stderr, in case stderr is already closed. :warn: may deadlock if output or error pipes are used and not handled separately. :raise GitCommandError: if the return status is not 0""" - - # stderr must be a bytes object as it will - # combined with more data from the process and - # decoded by the caller if stderr is None: stderr = b'' - elif type(stderr) == unicode: - stderr = stderr.encode(defenc) - + stderr = force_bytes(stderr) + status = self.proc.wait() def read_all_from_possibly_closed_stream(stream): try: - last_stderr = stream.read() - if type(last_stderr) == unicode: - last_stderr = last_stderr.encode(defenc) - return stderr + last_stderr + return stderr + force_bytes(stream.read()) except ValueError: return stderr or b'' @@ -633,8 +614,8 @@ class Git(LazyMixin): cwd=cwd, bufsize=-1, stdin=istream, - stderr=PIPE, - stdout=PIPE, + stderr=PIPE, + stdout=PIPE if with_stdout else open(os.devnull, 'wb'), shell=self.USE_SHELL, close_fds=(os.name == 'posix'), # unsupported on windows universal_newlines=universal_newlines, |