Skip to content

Commit 882ebb1

Browse files
uri-canvaByron
authored andcommitted
Take advantage of universal newlines.
1 parent fdb1dc7 commit 882ebb1

File tree

1 file changed

+83
-90
lines changed

1 file changed

+83
-90
lines changed

git/util.py

+83-90
Original file line numberDiff line numberDiff line change
@@ -379,101 +379,94 @@ def _parse_progress_line(self, line):
379379
380380
- Lines that do not contain progress info are stored in :attr:`other_lines`.
381381
- Lines that seem to contain an error (i.e. start with error: or fatal:) are stored
382-
in :attr:`error_lines`.
383-
384-
:return: list(line, ...) list of lines that could not be processed"""
382+
in :attr:`error_lines`."""
385383
# handle
386384
# Counting objects: 4, done.
387-
# Compressing objects: 50% (1/2) \rCompressing objects: 100% (2/2) \rCompressing objects: 100% (2/2), done.
385+
# Compressing objects: 50% (1/2)
386+
# Compressing objects: 100% (2/2)
387+
# Compressing objects: 100% (2/2), done.
388388
self._cur_line = line = line.decode('utf-8') if isinstance(line, bytes) else line
389389
if len(self.error_lines) > 0 or self._cur_line.startswith(('error:', 'fatal:')):
390390
self.error_lines.append(self._cur_line)
391-
return []
392-
393-
sub_lines = line.split('\r')
394-
failed_lines = []
395-
for sline in sub_lines:
396-
# find escape characters and cut them away - regex will not work with
397-
# them as they are non-ascii. As git might expect a tty, it will send them
398-
last_valid_index = None
399-
for i, c in enumerate(reversed(sline)):
400-
if ord(c) < 32:
401-
# its a slice index
402-
last_valid_index = -i - 1
403-
# END character was non-ascii
404-
# END for each character in sline
405-
if last_valid_index is not None:
406-
sline = sline[:last_valid_index]
407-
# END cut away invalid part
408-
sline = sline.rstrip()
409-
410-
cur_count, max_count = None, None
411-
match = self.re_op_relative.match(sline)
412-
if match is None:
413-
match = self.re_op_absolute.match(sline)
414-
415-
if not match:
416-
self.line_dropped(sline)
417-
failed_lines.append(sline)
418-
continue
419-
# END could not get match
420-
421-
op_code = 0
422-
remote, op_name, percent, cur_count, max_count, message = match.groups() # @UnusedVariable
423-
424-
# get operation id
425-
if op_name == "Counting objects":
426-
op_code |= self.COUNTING
427-
elif op_name == "Compressing objects":
428-
op_code |= self.COMPRESSING
429-
elif op_name == "Writing objects":
430-
op_code |= self.WRITING
431-
elif op_name == 'Receiving objects':
432-
op_code |= self.RECEIVING
433-
elif op_name == 'Resolving deltas':
434-
op_code |= self.RESOLVING
435-
elif op_name == 'Finding sources':
436-
op_code |= self.FINDING_SOURCES
437-
elif op_name == 'Checking out files':
438-
op_code |= self.CHECKING_OUT
439-
else:
440-
# Note: On windows it can happen that partial lines are sent
441-
# Hence we get something like "CompreReceiving objects", which is
442-
# a blend of "Compressing objects" and "Receiving objects".
443-
# This can't really be prevented, so we drop the line verbosely
444-
# to make sure we get informed in case the process spits out new
445-
# commands at some point.
446-
self.line_dropped(sline)
447-
# Note: Don't add this line to the failed lines, as we have to silently
448-
# drop it
449-
self.other_lines.extend(failed_lines)
450-
return failed_lines
451-
# END handle op code
452-
453-
# figure out stage
454-
if op_code not in self._seen_ops:
455-
self._seen_ops.append(op_code)
456-
op_code |= self.BEGIN
457-
# END begin opcode
458-
459-
if message is None:
460-
message = ''
461-
# END message handling
462-
463-
message = message.strip()
464-
if message.endswith(self.DONE_TOKEN):
465-
op_code |= self.END
466-
message = message[:-len(self.DONE_TOKEN)]
467-
# END end message handling
468-
message = message.strip(self.TOKEN_SEPARATOR)
469-
470-
self.update(op_code,
471-
cur_count and float(cur_count),
472-
max_count and float(max_count),
473-
message)
474-
# END for each sub line
475-
self.other_lines.extend(failed_lines)
476-
return failed_lines
391+
return
392+
393+
# find escape characters and cut them away - regex will not work with
394+
# them as they are non-ascii. As git might expect a tty, it will send them
395+
last_valid_index = None
396+
for i, c in enumerate(reversed(line)):
397+
if ord(c) < 32:
398+
# its a slice index
399+
last_valid_index = -i - 1
400+
# END character was non-ascii
401+
# END for each character in line
402+
if last_valid_index is not None:
403+
line = line[:last_valid_index]
404+
# END cut away invalid part
405+
line = line.rstrip()
406+
407+
cur_count, max_count = None, None
408+
match = self.re_op_relative.match(line)
409+
if match is None:
410+
match = self.re_op_absolute.match(line)
411+
412+
if not match:
413+
self.line_dropped(line)
414+
self.other_lines.append(line)
415+
return
416+
# END could not get match
417+
418+
op_code = 0
419+
remote, op_name, percent, cur_count, max_count, message = match.groups() # @UnusedVariable
420+
421+
# get operation id
422+
if op_name == "Counting objects":
423+
op_code |= self.COUNTING
424+
elif op_name == "Compressing objects":
425+
op_code |= self.COMPRESSING
426+
elif op_name == "Writing objects":
427+
op_code |= self.WRITING
428+
elif op_name == 'Receiving objects':
429+
op_code |= self.RECEIVING
430+
elif op_name == 'Resolving deltas':
431+
op_code |= self.RESOLVING
432+
elif op_name == 'Finding sources':
433+
op_code |= self.FINDING_SOURCES
434+
elif op_name == 'Checking out files':
435+
op_code |= self.CHECKING_OUT
436+
else:
437+
# Note: On windows it can happen that partial lines are sent
438+
# Hence we get something like "CompreReceiving objects", which is
439+
# a blend of "Compressing objects" and "Receiving objects".
440+
# This can't really be prevented, so we drop the line verbosely
441+
# to make sure we get informed in case the process spits out new
442+
# commands at some point.
443+
self.line_dropped(line)
444+
# Note: Don't add this line to the other lines, as we have to silently
445+
# drop it
446+
return
447+
# END handle op code
448+
449+
# figure out stage
450+
if op_code not in self._seen_ops:
451+
self._seen_ops.append(op_code)
452+
op_code |= self.BEGIN
453+
# END begin opcode
454+
455+
if message is None:
456+
message = ''
457+
# END message handling
458+
459+
message = message.strip()
460+
if message.endswith(self.DONE_TOKEN):
461+
op_code |= self.END
462+
message = message[:-len(self.DONE_TOKEN)]
463+
# END end message handling
464+
message = message.strip(self.TOKEN_SEPARATOR)
465+
466+
self.update(op_code,
467+
cur_count and float(cur_count),
468+
max_count and float(max_count),
469+
message)
477470

478471
def new_message_handler(self):
479472
"""

0 commit comments

Comments
 (0)