@@ -58,6 +58,22 @@ def add_progress(kwargs, git, progress):
58
58
59
59
#} END utilities
60
60
61
+ def progress_object (progress ):
62
+ """Given the 'progress' return a suitable object derived from
63
+ RemoteProgress().
64
+ """
65
+ # new API only needs progress as a function
66
+ if callable (progress ):
67
+ return RemoteProgress (progress )
68
+
69
+ # where None is passed create a parser that eats the progress
70
+ elif progress is None :
71
+ return RemoteProgress ()
72
+
73
+ # assume its the old API with an instance of RemoteProgress.
74
+ else :
75
+ return progress
76
+
61
77
62
78
class PushInfo (object ):
63
79
@@ -536,7 +552,10 @@ def update(self, **kwargs):
536
552
self .repo .git .remote (scmd , self .name , ** kwargs )
537
553
return self
538
554
555
+
539
556
def _get_fetch_info_from_stderr (self , proc , progress ):
557
+ progress = progress_object (progress )
558
+
540
559
# skip first line as it is some remote info we are not interested in
541
560
output = IterableList ('name' )
542
561
@@ -591,6 +610,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
591
610
return output
592
611
593
612
def _get_push_info (self , proc , progress ):
613
+ progress = progress_object (progress )
614
+
594
615
# read progress information from stderr
595
616
# we hope stdout can hold all the data, it should ...
596
617
# read the lines manually as it will use carriage returns between the messages
@@ -665,7 +686,7 @@ def fetch(self, refspec=None, progress=None, **kwargs):
665
686
666
687
proc = self .repo .git .fetch (self , * args , as_process = True , with_stdout = False ,
667
688
universal_newlines = True , v = True , ** kwargs )
668
- res = self ._get_fetch_info_from_stderr (proc , progress or RemoteProgress () )
689
+ res = self ._get_fetch_info_from_stderr (proc , progress )
669
690
if hasattr (self .repo .odb , 'update_cache' ):
670
691
self .repo .odb .update_cache ()
671
692
return res
@@ -684,7 +705,7 @@ def pull(self, refspec=None, progress=None, **kwargs):
684
705
kwargs = add_progress (kwargs , self .repo .git , progress )
685
706
proc = self .repo .git .pull (self , refspec , with_stdout = False , as_process = True ,
686
707
universal_newlines = True , v = True , ** kwargs )
687
- res = self ._get_fetch_info_from_stderr (proc , progress or RemoteProgress () )
708
+ res = self ._get_fetch_info_from_stderr (proc , progress )
688
709
if hasattr (self .repo .odb , 'update_cache' ):
689
710
self .repo .odb .update_cache ()
690
711
return res
@@ -694,10 +715,26 @@ def push(self, refspec=None, progress=None, **kwargs):
694
715
695
716
:param refspec: see 'fetch' method
696
717
:param progress:
697
- Instance of type RemoteProgress allowing the caller to receive
698
- progress information until the method returns.
699
718
If None, progress information will be discarded
700
719
720
+ No further progress information is returned after push returns.
721
+
722
+ A function (callable) that is called with the progress infomation:
723
+
724
+ progress( op_code, cur_count, max_count=None, message='' )
725
+
726
+ op_code is a bit mask of values defined in git.RemoteProgress
727
+
728
+ cur_count and max_count are float values.
729
+
730
+ max_count is None if there is no max_count
731
+
732
+ messages is '' if there is no additon message.
733
+
734
+ Deprecated: Pass in a class derived from git.RemoteProgres that
735
+ overrides the update() function.
736
+
737
+
701
738
:param kwargs: Additional arguments to be passed to git-push
702
739
:return:
703
740
IterableList(PushInfo, ...) iterable list of PushInfo instances, each
@@ -710,7 +747,7 @@ def push(self, refspec=None, progress=None, **kwargs):
710
747
kwargs = add_progress (kwargs , self .repo .git , progress )
711
748
proc = self .repo .git .push (self , refspec , porcelain = True , as_process = True ,
712
749
universal_newlines = True , ** kwargs )
713
- return self ._get_push_info (proc , progress or RemoteProgress () )
750
+ return self ._get_push_info (proc , progress )
714
751
715
752
@property
716
753
def config_reader (self ):
0 commit comments