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

Commitb4492c7

Browse files
committed
The progress arg to push, pull, fetch and clone is now a python callable.
This simplifies the API and removes the parser, RemoteProgres,from the API as RemoteProgress is an internal detail of the implementation.progress is accepted as:* None - drop progress messages* callable (function etc) - call the function with the same args as update* object - assume its RemoteProgress derived as use as beforeRemoteProgress takes an optional progress_function argument.It will call the progress function if not None otherwise call self.updateas it used to.
1 parentbed4630 commitb4492c7

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
@@ -57,6 +57,22 @@ def add_progress(kwargs, git, progress):
5757

5858
#} END utilities
5959

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

6177
classPushInfo(object):
6278

@@ -535,7 +551,10 @@ def update(self, **kwargs):
535551
self.repo.git.remote(scmd,self.name,**kwargs)
536552
returnself
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
returnoutput
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,progressorRemoteProgress())
678+
res=self._get_fetch_info_from_stderr(proc,progress)
658679
ifhasattr(self.repo.odb,'update_cache'):
659680
self.repo.odb.update_cache()
660681
returnres
@@ -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,progressorRemoteProgress())
696+
res=self._get_fetch_info_from_stderr(proc,progress)
676697
ifhasattr(self.repo.odb,'update_cache'):
677698
self.repo.odb.update_cache()
678699
returnres
@@ -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-
returnself._get_push_info(proc,progressorRemoteProgress())
737+
returnself._get_push_info(proc,progress)
701738

702739
@property
703740
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