3131 join_path ,
3232 finalize_process
3333)
34+ from git .cmd import handle_process_output
3435from gitdb .util import join
3536from git .compat import defenc
3637
4041#{ Utilities
4142
4243
43- def digest_process_messages (fh , progress ):
44- """Read progress messages from file-like object fh, supplying the respective
45- progress messages to the progress instance.
46-
47- :param fh: File handle to read from
48- :return: list(line, ...) list of lines without linebreaks that did
49- not contain progress information"""
50- line_so_far = b''
51- dropped_lines = list ()
52- while True :
53- char = fh .read (1 ) # reads individual single byte strings
54- if not char :
55- break
56-
57- if char in (b'\r ' , b'\n ' ) and line_so_far :
58- dropped_lines .extend (progress ._parse_progress_line (line_so_far .decode (defenc )))
59- line_so_far = b''
60- else :
61- line_so_far += char
62- # END process parsed line
63- # END while file is not done reading
64- return dropped_lines
65-
66-
6744def add_progress (kwargs , git , progress ):
6845 """Add the --progress flag to the given kwargs dict if supported by the
6946 git command. If the actual progress in the given progress instance is not
@@ -532,17 +509,25 @@ def _get_fetch_info_from_stderr(self, proc, progress):
532509 # Basically we want all fetch info lines which appear to be in regular form, and thus have a
533510 # command character. Everything else we ignore,
534511 cmds = set (PushInfo ._flag_map .keys ()) & set (FetchInfo ._flag_map .keys ())
535- for line in digest_process_messages (proc .stderr , progress ):
536- if line .startswith ('fatal:' ):
537- raise GitCommandError (("Error when fetching: %s" % line ,), 2 )
538- # END handle special messages
539- for cmd in cmds :
540- if line [1 ] == cmd :
541- fetch_info_lines .append (line )
542- continue
543- # end find command code
544- # end for each comand code we know
545- # END for each line
512+
513+ progress_handler = progress .new_message_handler ()
514+
515+ def my_progress_handler (line ):
516+ for pline in progress_handler (line ):
517+ if line .startswith ('fatal:' ):
518+ raise GitCommandError (("Error when fetching: %s" % line ,), 2 )
519+ # END handle special messages
520+ for cmd in cmds :
521+ if line [1 ] == cmd :
522+ fetch_info_lines .append (line )
523+ continue
524+ # end find command code
525+ # end for each comand code we know
526+ # end for each line progress didn't handle
527+ # end
528+
529+ # We are only interested in stderr here ...
530+ handle_process_output (proc , None , my_progress_handler , finalize_process )
546531
547532 # read head information
548533 fp = open (join (self .repo .git_dir , 'FETCH_HEAD' ), 'rb' )
@@ -555,7 +540,6 @@ def _get_fetch_info_from_stderr(self, proc, progress):
555540
556541 output .extend (FetchInfo ._from_line (self .repo , err_line , fetch_line )
557542 for err_line , fetch_line in zip (fetch_info_lines , fetch_head_info ))
558- finalize_process (proc )
559543 return output
560544
561545 def _get_push_info (self , proc , progress ):
@@ -564,19 +548,19 @@ def _get_push_info(self, proc, progress):
564548 # read the lines manually as it will use carriage returns between the messages
565549 # to override the previous one. This is why we read the bytes manually
566550 # TODO: poll() on file descriptors to know what to read next, process streams concurrently
567- digest_process_messages (proc .stderr , progress )
568-
551+ progress_handler = progress .new_message_handler ()
569552 output = IterableList ('name' )
570- for line in proc . stdout . readlines ():
571- line = line . decode ( defenc )
553+
554+ def stdout_handler ( line ):
572555 try :
573556 output .append (PushInfo ._from_line (self , line ))
574557 except ValueError :
575558 # if an error happens, additional info is given which we cannot parse
576559 pass
577560 # END exception handling
578561 # END for each line
579- finalize_process (proc )
562+
563+ handle_process_output (proc , stdout_handler , progress_handler , finalize_process )
580564 return output
581565
582566 def fetch (self , refspec = None , progress = None , ** kwargs ):
0 commit comments