Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitece57af

Browse files
committed
Merge pull requestgitpython-developers#450 from barry-scott/master
The progress arg to push, pull, fetch and clone is now a python calla…
2 parentsc5077da +d255f4c commitece57af

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

‎git/remote.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ def add_progress(kwargs, git, progress):
5858

5959
#} END utilities
6060

61+
defprogress_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+
ifcallable(progress):
67+
returnRemoteProgress(progress)
68+
69+
# where None is passed create a parser that eats the progress
70+
elifprogressisNone:
71+
returnRemoteProgress()
72+
73+
# assume its the old API with an instance of RemoteProgress.
74+
else:
75+
returnprogress
76+
6177

6278
classPushInfo(object):
6379

@@ -536,7 +552,10 @@ def update(self, **kwargs):
536552
self.repo.git.remote(scmd,self.name,**kwargs)
537553
returnself
538554

555+
539556
def_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
541560
output=IterableList('name')
542561

@@ -591,6 +610,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
591610
returnoutput
592611

593612
def_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

666687
proc=self.repo.git.fetch(self,*args,as_process=True,with_stdout=False,
667688
universal_newlines=True,v=True,**kwargs)
668-
res=self._get_fetch_info_from_stderr(proc,progressorRemoteProgress())
689+
res=self._get_fetch_info_from_stderr(proc,progress)
669690
ifhasattr(self.repo.odb,'update_cache'):
670691
self.repo.odb.update_cache()
671692
returnres
@@ -684,7 +705,7 @@ def pull(self, refspec=None, progress=None, **kwargs):
684705
kwargs=add_progress(kwargs,self.repo.git,progress)
685706
proc=self.repo.git.pull(self,refspec,with_stdout=False,as_process=True,
686707
universal_newlines=True,v=True,**kwargs)
687-
res=self._get_fetch_info_from_stderr(proc,progressorRemoteProgress())
708+
res=self._get_fetch_info_from_stderr(proc,progress)
688709
ifhasattr(self.repo.odb,'update_cache'):
689710
self.repo.odb.update_cache()
690711
returnres
@@ -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):
710747
kwargs=add_progress(kwargs,self.repo.git,progress)
711748
proc=self.repo.git.push(self,refspec,porcelain=True,as_process=True,
712749
universal_newlines=True,**kwargs)
713-
returnself._get_push_info(proc,progressorRemoteProgress())
750+
returnself._get_push_info(proc,progress)
714751

715752
@property
716753
defconfig_reader(self):

‎git/repo/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
fromgit.configimportGitConfigParser
3333
fromgit.remoteimport (
3434
Remote,
35-
add_progress
35+
add_progress,
36+
progress_object
3637
)
3738

3839
fromgit.dbimportGitCmdObjectDB
@@ -872,6 +873,8 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
872873

873874
@classmethod
874875
def_clone(cls,git,url,path,odb_default_type,progress,**kwargs):
876+
progress=progress_object(progress)
877+
875878
# special handling for windows for path at which the clone should be
876879
# created.
877880
# tilde '~' will be expanded to the HOME no matter where the ~ occours. Hence

‎git/util.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,16 @@ class RemoteProgress(object):
174174
DONE_TOKEN='done.'
175175
TOKEN_SEPARATOR=', '
176176

177-
__slots__= ("_cur_line","_seen_ops")
177+
__slots__= ("_cur_line","_seen_ops","__progress_function")
178178
re_op_absolute=re.compile(r"(remote: )?([\w\s]+):\s+()(\d+)()(.*)")
179179
re_op_relative=re.compile(r"(remote: )?([\w\s]+):\s+(\d+)% \((\d+)/(\d+)\)(.*)")
180180

181-
def__init__(self):
181+
def__init__(self,progress_function=None):
182+
ifprogress_functionisnotNone:
183+
self.__progress_function=progress_function
184+
else:
185+
self.__progress_function=self.update
186+
182187
self._seen_ops=list()
183188
self._cur_line=None
184189

@@ -267,7 +272,7 @@ def _parse_progress_line(self, line):
267272
# END end message handling
268273
message=message.strip(self.TOKEN_SEPARATOR)
269274

270-
self.update(op_code,
275+
self.__progress_function(op_code,
271276
cur_countandfloat(cur_count),
272277
max_countandfloat(max_count),
273278
message)
@@ -314,7 +319,6 @@ def update(self, op_code, cur_count, max_count=None, message=''):
314319
You may read the contents of the current line in self._cur_line"""
315320
pass
316321

317-
318322
classActor(object):
319323

320324
"""Actors hold information about a person acting on the repository. They

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp