@@ -58,6 +58,22 @@ def add_progress(kwargs, git, progress):
5858
5959#} END utilities
6060
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+
6177
6278class PushInfo (object ):
6379
@@ -536,7 +552,10 @@ def update(self, **kwargs):
536552self .repo .git .remote (scmd ,self .name ,** kwargs )
537553return self
538554
555+
539556def _get_fetch_info_from_stderr (self ,proc ,progress ):
557+ progress = progress_object (progress )
558+
540559# skip first line as it is some remote info we are not interested in
541560output = IterableList ('name' )
542561
@@ -591,6 +610,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
591610return output
592611
593612def _get_push_info (self ,proc ,progress ):
613+ progress = progress_object (progress )
614+
594615# read progress information from stderr
595616# we hope stdout can hold all the data, it should ...
596617# 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):
665686
666687proc = self .repo .git .fetch (self ,* args ,as_process = True ,with_stdout = False ,
667688universal_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 )
669690if hasattr (self .repo .odb ,'update_cache' ):
670691self .repo .odb .update_cache ()
671692return res
@@ -684,7 +705,7 @@ def pull(self, refspec=None, progress=None, **kwargs):
684705kwargs = add_progress (kwargs ,self .repo .git ,progress )
685706proc = self .repo .git .pull (self ,refspec ,with_stdout = False ,as_process = True ,
686707universal_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 )
688709if hasattr (self .repo .odb ,'update_cache' ):
689710self .repo .odb .update_cache ()
690711return res
@@ -694,10 +715,26 @@ def push(self, refspec=None, progress=None, **kwargs):
694715
695716 :param refspec: see 'fetch' method
696717 :param progress:
697- Instance of type RemoteProgress allowing the caller to receive
698- progress information until the method returns.
699718 If None, progress information will be discarded
700719
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+
701738 :param kwargs: Additional arguments to be passed to git-push
702739 :return:
703740 IterableList(PushInfo, ...) iterable list of PushInfo instances, each
@@ -710,7 +747,7 @@ def push(self, refspec=None, progress=None, **kwargs):
710747kwargs = add_progress (kwargs ,self .repo .git ,progress )
711748proc = self .repo .git .push (self ,refspec ,porcelain = True ,as_process = True ,
712749universal_newlines = True ,** kwargs )
713- return self ._get_push_info (proc ,progress or RemoteProgress () )
750+ return self ._get_push_info (proc ,progress )
714751
715752@property
716753def config_reader (self ):