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

Commit2972481

Browse files
committed
fix(remote): Add CallableRemoteProgress
That way, the base type doesn't need any adjustment.Related to#450
1 parentce87a2b commit2972481

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

‎git/remote.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
LazyMixin,
2525
Iterable,
2626
IterableList,
27-
RemoteProgress
27+
RemoteProgress,
28+
CallableRemoteProgress
2829
)
2930
fromgit.utilimport (
3031
join_path,
@@ -65,7 +66,7 @@ def to_progress_instance(progress):
6566
"""
6667
# new API only needs progress as a function
6768
ifcallable(progress):
68-
returnRemoteProgress(progress)
69+
returnCallableRemoteProgress(progress)
6970

7071
# where None is passed create a parser that eats the progress
7172
elifprogressisNone:

‎git/util.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
__all__= ("stream_copy","join_path","to_native_path_windows","to_native_path_linux",
4040
"join_path_native","Stats","IndexFileSHA1Writer","Iterable","IterableList",
4141
"BlockingLockFile","LockFile",'Actor','get_user_id','assure_directory_exists',
42-
'RemoteProgress','rmtree','WaitGroup','unbare_repo')
42+
'RemoteProgress','CallableRemoteProgress','rmtree','WaitGroup','unbare_repo')
4343

4444
#{ Utility Methods
4545

@@ -160,7 +160,6 @@ def finalize_process(proc, **kwargs):
160160

161161

162162
classRemoteProgress(object):
163-
164163
"""
165164
Handler providing an interface to parse progress information emitted by git-push
166165
and git-fetch and to dispatch callbacks allowing subclasses to react to the progress.
@@ -174,12 +173,11 @@ class RemoteProgress(object):
174173
DONE_TOKEN='done.'
175174
TOKEN_SEPARATOR=', '
176175

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

181-
def__init__(self,progress_function=None):
182-
self.__progress_function=progress_functionifprogress_functionelseself.update
180+
def__init__(self):
183181
self._seen_ops=list()
184182
self._cur_line=None
185183

@@ -268,10 +266,10 @@ def _parse_progress_line(self, line):
268266
# END end message handling
269267
message=message.strip(self.TOKEN_SEPARATOR)
270268

271-
self.__progress_function(op_code,
272-
cur_countandfloat(cur_count),
273-
max_countandfloat(max_count),
274-
message)
269+
self.update(op_code,
270+
cur_countandfloat(cur_count),
271+
max_countandfloat(max_count),
272+
message)
275273
# END for each sub line
276274
returnfailed_lines
277275

@@ -314,7 +312,18 @@ def update(self, op_code, cur_count, max_count=None, message=''):
314312
315313
You may read the contents of the current line in self._cur_line"""
316314
pass
317-
315+
316+
317+
classCallableRemoteProgress(RemoteProgress):
318+
"""An implementation forwarding updates to any callable"""
319+
__slots__= ('_callable')
320+
321+
def__init__(self,fn):
322+
self._callable=fn
323+
324+
defupdate(self,*args,**kwargs):
325+
self._callable(*args,**kwargs)
326+
318327

319328
classActor(object):
320329

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp