summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2016-06-13 10:07:40 +0200
committerSebastian Thiel <byronimo@gmail.com>2016-06-13 10:07:40 +0200
commit15ee5a505b43741cdb7c79f41ebfa3d881910a6c (patch)
tree53d38efc5e78a7114f0727192cfc156d992b91c3
parentda86442f6a7bf1263fb5aafdaf904ed2f7db839f (diff)
downloadgitpython-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.
-rw-r--r--git/cmd.py31
m---------git/ext/gitdb0
-rw-r--r--git/remote.py22
-rw-r--r--git/util.py12
4 files changed, 17 insertions, 48 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 633aedcb..9a141297 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -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,
diff --git a/git/ext/gitdb b/git/ext/gitdb
-Subproject d1996e04dbf4841b853b60c1365f0f5fd28d170
+Subproject 2389b75280efb1a63e6ea578eae7f897fd4beb1
diff --git a/git/remote.py b/git/remote.py
index 12a681b0..347d2844 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -570,16 +570,11 @@ class Remote(LazyMixin, Iterable):
progress_handler = progress.new_message_handler()
- error_message = None
stderr_text = None
for line in proc.stderr:
line = force_text(line)
for pline in progress_handler(line):
- if line.startswith('fatal:') or line.startswith('error:'):
- error_message = "Error when fetching: %s" % (line,)
- break
-
# END handle special messages
for cmd in cmds:
if len(line) > 1 and line[0] == ' ' and line[1] == cmd:
@@ -587,20 +582,13 @@ class Remote(LazyMixin, Iterable):
continue
# end find command code
# end for each comand code we know
-
- if error_message is not None:
- break
# end for each line progress didn't handle
-
- if error_message is not None:
- stderr_text = proc.stderr.read()
-
# end
+ if progress.error_lines():
+ stderr_text = '\n'.join(progress.error_lines())
+
finalize_process(proc, stderr=stderr_text)
- if error_message is not None:
- raise GitCommandError(error_message, 2, stderr=stderr_text)
-
# read head information
fp = open(join(self.repo.git_dir, 'FETCH_HEAD'), 'rb')
fetch_head_info = [l.decode(defenc) for l in fp.readlines()]
@@ -646,10 +634,6 @@ class Remote(LazyMixin, Iterable):
try:
handle_process_output(proc, stdout_handler, progress_handler, finalize_process)
- except GitCommandError as err:
- # convert any error from wait() into the same error with stdout lines
- raise GitCommandError(err.command, err.status, progress.get_stderr())
-
except Exception:
if len(output) == 0:
raise
diff --git a/git/util.py b/git/util.py
index 706518b8..f5c69231 100644
--- a/git/util.py
+++ b/git/util.py
@@ -182,12 +182,16 @@ class RemoteProgress(object):
self._cur_line = None
self._error_lines = []
- def get_stderr(self):
- return '\n'.join(self._error_lines)
+ def error_lines(self):
+ """Returns all lines that started with error: or fatal:"""
+ return self._error_lines
def _parse_progress_line(self, line):
"""Parse progress information from the given line as retrieved by git-push
- or git-fetch
+ or git-fetch.
+
+ Lines that seem to contain an error (i.e. start with error: or fatal:) are stored
+ separately and can be queried using `error_lines()`.
:return: list(line, ...) list of lines that could not be processed"""
# handle
@@ -775,7 +779,7 @@ class WaitGroup(object):
def wait(self, stderr=b''):
self.cv.acquire()
while self.count > 0:
- self.cv.wait(strerr=stderr)
+ self.cv.wait()
self.cv.release()