@@ -57,6 +57,22 @@ def add_progress(kwargs, git, progress):
5757
5858#} END utilities
5959
60+ def progress_object (progress ):
61+ """Given the 'progress' return a suitable object derived from
62+ RemoteProgress().
63+ """
64+ # new API only needs progress as a function
65+ if callable (progress ):
66+ return RemoteProgress (progress )
67+
68+ # where None is passed create a parser that eats the progress
69+ elif progress is None :
70+ return RemoteProgress ()
71+
72+ # assume its the old API with an instance of RemoteProgress.
73+ else :
74+ return progress
75+
6076
6177class PushInfo (object ):
6278
@@ -535,7 +551,10 @@ def update(self, **kwargs):
535551 self .repo .git .remote (scmd , self .name , ** kwargs )
536552 return self
537553
554+
538555 def _get_fetch_info_from_stderr (self , proc , progress ):
556+ progress = progress_object (progress )
557+
539558 # skip first line as it is some remote info we are not interested in
540559 output = IterableList ('name' )
541560
@@ -580,6 +599,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
580599 return output
581600
582601 def _get_push_info (self , proc , progress ):
602+ progress = progress_object (progress )
603+
583604 # read progress information from stderr
584605 # we hope stdout can hold all the data, it should ...
585606 # read the lines manually as it will use carriage returns between the messages
@@ -654,7 +675,7 @@ def fetch(self, refspec=None, progress=None, **kwargs):
654675
655676 proc = self .repo .git .fetch (self , * args , as_process = True , with_stdout = False , v = True ,
656677 ** kwargs )
657- res = self ._get_fetch_info_from_stderr (proc , progress or RemoteProgress () )
678+ res = self ._get_fetch_info_from_stderr (proc , progress )
658679 if hasattr (self .repo .odb , 'update_cache' ):
659680 self .repo .odb .update_cache ()
660681 return res
@@ -672,7 +693,7 @@ def pull(self, refspec=None, progress=None, **kwargs):
672693 self ._assert_refspec ()
673694 kwargs = add_progress (kwargs , self .repo .git , progress )
674695 proc = self .repo .git .pull (self , refspec , with_stdout = False , as_process = True , v = True , ** kwargs )
675- res = self ._get_fetch_info_from_stderr (proc , progress or RemoteProgress () )
696+ res = self ._get_fetch_info_from_stderr (proc , progress )
676697 if hasattr (self .repo .odb , 'update_cache' ):
677698 self .repo .odb .update_cache ()
678699 return res
@@ -682,10 +703,26 @@ def push(self, refspec=None, progress=None, **kwargs):
682703
683704 :param refspec: see 'fetch' method
684705 :param progress:
685- Instance of type RemoteProgress allowing the caller to receive
686- progress information until the method returns.
687706 If None, progress information will be discarded
688707
708+ No further progress information is returned after push returns.
709+
710+ A function (callable) that is called with the progress infomation:
711+
712+ progress( op_code, cur_count, max_count=None, message='' )
713+
714+ op_code is a bit mask of values defined in git.RemoteProgress
715+
716+ cur_count and max_count are float values.
717+
718+ max_count is None if there is no max_count
719+
720+ messages is '' if there is no additon message.
721+
722+ Deprecated: Pass in a class derived from git.RemoteProgres that
723+ overrides the update() function.
724+
725+
689726 :param kwargs: Additional arguments to be passed to git-push
690727 :return:
691728 IterableList(PushInfo, ...) iterable list of PushInfo instances, each
@@ -697,7 +734,7 @@ def push(self, refspec=None, progress=None, **kwargs):
697734 be null."""
698735 kwargs = add_progress (kwargs , self .repo .git , progress )
699736 proc = self .repo .git .push (self , refspec , porcelain = True , as_process = True , ** kwargs )
700- return self ._get_push_info (proc , progress or RemoteProgress () )
737+ return self ._get_push_info (proc , progress )
701738
702739 @property
703740 def config_reader (self ):
0 commit comments