summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-09-28 17:10:59 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-09-28 17:55:57 +0200
commit6e98416791566f44a407dcac07a1e1f1b0483544 (patch)
tree36ec45d49a2da3dca0e8a590456e74f113112a77
parent44c6d0b368bc1ec6cd0a97b01678b38788c9bd9c (diff)
downloadgitpython-6e98416791566f44a407dcac07a1e1f1b0483544.tar.gz
remote, #519: INCOMPLETE FIX-2 double-decoding push-infos
+ Unicode PY2/3 issues fixed also in pump stream func.
-rw-r--r--git/cmd.py30
-rw-r--r--git/exc.py3
-rw-r--r--git/test/lib/helper.py3
3 files changed, 23 insertions, 13 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 20da96bd..835be605 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -88,18 +88,26 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer, de
Set it to False if `universal_newline == True` (then streams are in text-mode)
or if decoding must happen later (i.e. for Diffs).
"""
+ if decode_streams:
+ ZERO = b''
+ LF = b'\n'
+ CR = b'\r'
+ else:
+ ZERO = u''
+ LF = u'\n'
+ CR = u'\r'
def _parse_lines_from_buffer(buf):
- line = b''
+ line = ZERO
bi = 0
lb = len(buf)
while bi < lb:
- char = _bchr(buf[bi])
+ char = buf[bi]
bi += 1
- if char in (b'\r', b'\n') and line:
- yield bi, line + b'\n'
- line = b''
+ if char in (LF, CR) and line:
+ yield bi, line + LF
+ line = ZERO
else:
line += char
# END process parsed line
@@ -107,7 +115,7 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer, de
# end
def _read_lines_from_fno(fno, last_buf_list):
- buf = os.read(fno, mmap.PAGESIZE)
+ buf = fno.read(mmap.PAGESIZE)
buf = last_buf_list[0] + buf
bi = 0
@@ -192,8 +200,8 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer, de
else:
# poll is preferred, as select is limited to file handles up to 1024 ... . This could otherwise be
# an issue for us, as it matters how many handles our own process has
- fdmap = {outfn: (stdout_handler, [b''], decode_streams),
- errfn: (stderr_handler, [b''], decode_streams)}
+ fdmap = {outfn: (process.stdout, stdout_handler, [ZERO], decode_streams),
+ errfn: (process.stderr, stderr_handler, [ZERO], decode_streams)}
READ_ONLY = select.POLLIN | select.POLLPRI | select.POLLHUP | select.POLLERR # @UndefinedVariable
CLOSED = select.POLLHUP | select.POLLERR # @UndefinedVariable
@@ -217,7 +225,7 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer, de
if result & CLOSED:
closed_streams.add(fd)
else:
- _dispatch_lines(fd, *fdmap[fd])
+ _dispatch_lines(*fdmap[fd])
# end handle closed stream
# end for each poll-result tuple
@@ -227,8 +235,8 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer, de
# end endless loop
# Depelete all remaining buffers
- for fno, (handler, buf_list, decode) in fdmap.items():
- _deplete_buffer(fno, handler, buf_list, decode)
+ for fno, args in fdmap.items():
+ _deplete_buffer(*args)
# end for each file handle
for fno in fdmap.keys():
diff --git a/git/exc.py b/git/exc.py
index 6c9cde34..47215c21 100644
--- a/git/exc.py
+++ b/git/exc.py
@@ -34,7 +34,8 @@ class CommandError(UnicodeMixin, Exception):
_msg = u"Cmd('%s') failed%s"
def __init__(self, command, status=None, stderr=None, stdout=None):
- assert isinstance(command, (tuple, list)), command
+ if not isinstance(command, (tuple, list)):
+ command = command.split()
self.command = command
self.status = status
if status:
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 949e474f..90d2b1e9 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -301,7 +301,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
try:
gd.proc.kill()
except:
- pass ## Either it has died (and we're here), or it won't die, again here...
+ ## Either it has died (and we're here), or it won't die, again here...
+ pass
rw_repo.git.clear_cache()
rw_remote_repo.git.clear_cache()