@@ -57,6 +57,22 @@ def add_progress(kwargs, git, progress):
57
57
58
58
#} END utilities
59
59
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
+
60
76
61
77
class PushInfo (object ):
62
78
@@ -535,7 +551,10 @@ def update(self, **kwargs):
535
551
self .repo .git .remote (scmd , self .name , ** kwargs )
536
552
return self
537
553
554
+
538
555
def _get_fetch_info_from_stderr (self , proc , progress ):
556
+ progress = progress_object (progress )
557
+
539
558
# skip first line as it is some remote info we are not interested in
540
559
output = IterableList ('name' )
541
560
@@ -580,6 +599,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
580
599
return output
581
600
582
601
def _get_push_info (self , proc , progress ):
602
+ progress = progress_object (progress )
603
+
583
604
# read progress information from stderr
584
605
# we hope stdout can hold all the data, it should ...
585
606
# 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):
654
675
655
676
proc = self .repo .git .fetch (self , * args , as_process = True , with_stdout = False , v = True ,
656
677
** kwargs )
657
- res = self ._get_fetch_info_from_stderr (proc , progress or RemoteProgress () )
678
+ res = self ._get_fetch_info_from_stderr (proc , progress )
658
679
if hasattr (self .repo .odb , 'update_cache' ):
659
680
self .repo .odb .update_cache ()
660
681
return res
@@ -672,7 +693,7 @@ def pull(self, refspec=None, progress=None, **kwargs):
672
693
self ._assert_refspec ()
673
694
kwargs = add_progress (kwargs , self .repo .git , progress )
674
695
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 )
676
697
if hasattr (self .repo .odb , 'update_cache' ):
677
698
self .repo .odb .update_cache ()
678
699
return res
@@ -682,10 +703,26 @@ def push(self, refspec=None, progress=None, **kwargs):
682
703
683
704
:param refspec: see 'fetch' method
684
705
:param progress:
685
- Instance of type RemoteProgress allowing the caller to receive
686
- progress information until the method returns.
687
706
If None, progress information will be discarded
688
707
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
+
689
726
:param kwargs: Additional arguments to be passed to git-push
690
727
:return:
691
728
IterableList(PushInfo, ...) iterable list of PushInfo instances, each
@@ -697,7 +734,7 @@ def push(self, refspec=None, progress=None, **kwargs):
697
734
be null."""
698
735
kwargs = add_progress (kwargs , self .repo .git , progress )
699
736
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 )
701
738
702
739
@property
703
740
def config_reader (self ):
0 commit comments