31
31
join_path ,
32
32
finalize_process
33
33
)
34
+ from git .cmd import handle_process_output
34
35
from gitdb .util import join
35
36
from git .compat import defenc
36
37
40
41
#{ Utilities
41
42
42
43
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
-
67
44
def add_progress (kwargs , git , progress ):
68
45
"""Add the --progress flag to the given kwargs dict if supported by the
69
46
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):
532
509
# Basically we want all fetch info lines which appear to be in regular form, and thus have a
533
510
# command character. Everything else we ignore,
534
511
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 )
546
531
547
532
# read head information
548
533
fp = open (join (self .repo .git_dir , 'FETCH_HEAD' ), 'rb' )
@@ -555,7 +540,6 @@ def _get_fetch_info_from_stderr(self, proc, progress):
555
540
556
541
output .extend (FetchInfo ._from_line (self .repo , err_line , fetch_line )
557
542
for err_line , fetch_line in zip (fetch_info_lines , fetch_head_info ))
558
- finalize_process (proc )
559
543
return output
560
544
561
545
def _get_push_info (self , proc , progress ):
@@ -564,19 +548,19 @@ def _get_push_info(self, proc, progress):
564
548
# read the lines manually as it will use carriage returns between the messages
565
549
# to override the previous one. This is why we read the bytes manually
566
550
# 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 ()
569
552
output = IterableList ('name' )
570
- for line in proc . stdout . readlines ():
571
- line = line . decode ( defenc )
553
+
554
+ def stdout_handler ( line ):
572
555
try :
573
556
output .append (PushInfo ._from_line (self , line ))
574
557
except ValueError :
575
558
# if an error happens, additional info is given which we cannot parse
576
559
pass
577
560
# END exception handling
578
561
# END for each line
579
- finalize_process (proc )
562
+
563
+ handle_process_output (proc , stdout_handler , progress_handler , finalize_process )
580
564
return output
581
565
582
566
def fetch (self , refspec = None , progress = None , ** kwargs ):
0 commit comments