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
3940
4041#{ Utilities
4142
42-
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-
6743def add_progress (kwargs , git , progress ):
6844 """Add the --progress flag to the given kwargs dict if supported by the
6945 git command. If the actual progress in the given progress instance is not
@@ -532,17 +508,24 @@ def _get_fetch_info_from_stderr(self, proc, progress):
532508 # Basically we want all fetch info lines which appear to be in regular form, and thus have a
533509 # command character. Everything else we ignore,
534510 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
511+
512+ progress_handler = progress .new_message_handler ()
513+ def my_progress_handler (line ):
514+ for pline in progress_handler (line ):
515+ if line .startswith ('fatal:' ):
516+ raise GitCommandError (("Error when fetching: %s" % line ,), 2 )
517+ # END handle special messages
518+ for cmd in cmds :
519+ if line [1 ] == cmd :
520+ fetch_info_lines .append (line )
521+ continue
522+ # end find command code
523+ # end for each comand code we know
524+ # end for each line progress didn't handle
525+ # end
526+
527+ # We are only interested in stderr here ...
528+ handle_process_output (proc , None , my_progress_handler , finalize_process )
546529
547530 # read head information
548531 fp = open (join (self .repo .git_dir , 'FETCH_HEAD' ), 'rb' )
@@ -555,7 +538,6 @@ def _get_fetch_info_from_stderr(self, proc, progress):
555538
556539 output .extend (FetchInfo ._from_line (self .repo , err_line , fetch_line )
557540 for err_line , fetch_line in zip (fetch_info_lines , fetch_head_info ))
558- finalize_process (proc )
559541 return output
560542
561543 def _get_push_info (self , proc , progress ):
@@ -564,19 +546,19 @@ def _get_push_info(self, proc, progress):
564546 # read the lines manually as it will use carriage returns between the messages
565547 # to override the previous one. This is why we read the bytes manually
566548 # TODO: poll() on file descriptors to know what to read next, process streams concurrently
567- digest_process_messages (proc .stderr , progress )
568-
549+ progress_handler = progress .new_message_handler ()
569550 output = IterableList ('name' )
570- for line in proc . stdout . readlines ():
571- line = line . decode ( defenc )
551+
552+ def stdout_handler ( line ):
572553 try :
573554 output .append (PushInfo ._from_line (self , line ))
574555 except ValueError :
575556 # if an error happens, additional info is given which we cannot parse
576557 pass
577558 # END exception handling
578559 # END for each line
579- finalize_process (proc )
560+
561+ handle_process_output (proc , stdout_handler , progress_handler , finalize_process )
580562 return output
581563
582564 def fetch (self , refspec = None , progress = None , ** kwargs ):
0 commit comments