Skip to content

Commit 2972481

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

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

‎git/remote.py

+3-2
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
from git.util import (
3031
join_path,
@@ -65,7 +66,7 @@ def to_progress_instance(progress):
6566
"""
6667
# new API only needs progress as a function
6768
if callable(progress):
68-
return RemoteProgress(progress)
69+
return CallableRemoteProgress(progress)
6970

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

‎git/util.py

+19-10
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
class RemoteProgress(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_function if progress_function else self.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_count and float(cur_count),
273-
max_count and float(max_count),
274-
message)
269+
self.update(op_code,
270+
cur_count and float(cur_count),
271+
max_count and float(max_count),
272+
message)
275273
# END for each sub line
276274
return failed_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+
class CallableRemoteProgress(RemoteProgress):
318+
"""An implementation forwarding updates to any callable"""
319+
__slots__ = ('_callable')
320+
321+
def __init__(self, fn):
322+
self._callable = fn
323+
324+
def update(self, *args, **kwargs):
325+
self._callable(*args, **kwargs)
326+
318327

319328
class Actor(object):
320329

0 commit comments

Comments
 (0)