Skip to content

Commit 6e98416

Browse files
committed
remote, #519: INCOMPLETE FIX-2 double-decoding push-infos
+ Unicode PY2/3 issues fixed also in pump stream func.
1 parent 44c6d0b commit 6e98416

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

‎git/cmd.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,34 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer, de
8888
Set it to False if `universal_newline == True` (then streams are in text-mode)
8989
or if decoding must happen later (i.e. for Diffs).
9090
"""
91+
if decode_streams:
92+
ZERO = b''
93+
LF = b'\n'
94+
CR = b'\r'
95+
else:
96+
ZERO = u''
97+
LF = u'\n'
98+
CR = u'\r'
9199

92100
def _parse_lines_from_buffer(buf):
93-
line = b''
101+
line = ZERO
94102
bi = 0
95103
lb = len(buf)
96104
while bi < lb:
97-
char = _bchr(buf[bi])
105+
char = buf[bi]
98106
bi += 1
99107

100-
if char in (b'\r', b'\n') and line:
101-
yield bi, line + b'\n'
102-
line = b''
108+
if char in (LF, CR) and line:
109+
yield bi, line + LF
110+
line = ZERO
103111
else:
104112
line += char
105113
# END process parsed line
106114
# END while file is not done reading
107115
# end
108116

109117
def _read_lines_from_fno(fno, last_buf_list):
110-
buf = os.read(fno, mmap.PAGESIZE)
118+
buf = fno.read(mmap.PAGESIZE)
111119
buf = last_buf_list[0] + buf
112120

113121
bi = 0
@@ -192,8 +200,8 @@ def pump_stream(cmdline, name, stream, is_decode, handler):
192200
else:
193201
# poll is preferred, as select is limited to file handles up to 1024 ... . This could otherwise be
194202
# an issue for us, as it matters how many handles our own process has
195-
fdmap = {outfn: (stdout_handler, [b''], decode_streams),
196-
errfn: (stderr_handler, [b''], decode_streams)}
203+
fdmap = {outfn: (process.stdout, stdout_handler, [ZERO], decode_streams),
204+
errfn: (process.stderr, stderr_handler, [ZERO], decode_streams)}
197205

198206
READ_ONLY = select.POLLIN | select.POLLPRI | select.POLLHUP | select.POLLERR # @UndefinedVariable
199207
CLOSED = select.POLLHUP | select.POLLERR # @UndefinedVariable
@@ -217,7 +225,7 @@ def pump_stream(cmdline, name, stream, is_decode, handler):
217225
if result & CLOSED:
218226
closed_streams.add(fd)
219227
else:
220-
_dispatch_lines(fd, *fdmap[fd])
228+
_dispatch_lines(*fdmap[fd])
221229
# end handle closed stream
222230
# end for each poll-result tuple
223231

@@ -227,8 +235,8 @@ def pump_stream(cmdline, name, stream, is_decode, handler):
227235
# end endless loop
228236

229237
# Depelete all remaining buffers
230-
for fno, (handler, buf_list, decode) in fdmap.items():
231-
_deplete_buffer(fno, handler, buf_list, decode)
238+
for fno, args in fdmap.items():
239+
_deplete_buffer(*args)
232240
# end for each file handle
233241

234242
for fno in fdmap.keys():

‎git/exc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class CommandError(UnicodeMixin, Exception):
3434
_msg = u"Cmd('%s') failed%s"
3535

3636
def __init__(self, command, status=None, stderr=None, stdout=None):
37-
assert isinstance(command, (tuple, list)), command
37+
if not isinstance(command, (tuple, list)):
38+
command = command.split()
3839
self.command = command
3940
self.status = status
4041
if status:

‎git/test/lib/helper.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ def remote_repo_creator(self):
301301
try:
302302
gd.proc.kill()
303303
except:
304-
pass ## Either it has died (and we're here), or it won't die, again here...
304+
## Either it has died (and we're here), or it won't die, again here...
305+
pass
305306

306307
rw_repo.git.clear_cache()
307308
rw_remote_repo.git.clear_cache()

0 commit comments

Comments
 (0)