Skip to content

The progress arg to push, pull, fetch and clone is now a python calla… #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ def add_progress(kwargs, git, progress):

#} END utilities

def progress_object(progress):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I would find to_progress_instance more descriptive when reading the code.

"""Given the 'progress' return a suitable object derived from
RemoteProgress().
"""
# new API only needs progress as a function
if callable(progress):
return RemoteProgress(progress)

# where None is passed create a parser that eats the progress
elif progress is None:
return RemoteProgress()

# assume its the old API with an instance of RemoteProgress.
else:
return progress


class PushInfo(object):

Expand Down Expand Up @@ -536,7 +552,10 @@ def update(self, **kwargs):
self.repo.git.remote(scmd, self.name, **kwargs)
return self


def _get_fetch_info_from_stderr(self, proc, progress):
progress = progress_object(progress)

# skip first line as it is some remote info we are not interested in
output = IterableList('name')

Expand Down Expand Up @@ -591,6 +610,8 @@ def _get_fetch_info_from_stderr(self, proc, progress):
return output

def _get_push_info(self, proc, progress):
progress = progress_object(progress)

# read progress information from stderr
# we hope stdout can hold all the data, it should ...
# read the lines manually as it will use carriage returns between the messages
Expand Down Expand Up @@ -665,7 +686,7 @@ def fetch(self, refspec=None, progress=None, **kwargs):

proc = self.repo.git.fetch(self, *args, as_process=True, with_stdout=False,
universal_newlines=True, v=True, **kwargs)
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
res = self._get_fetch_info_from_stderr(proc, progress)
if hasattr(self.repo.odb, 'update_cache'):
self.repo.odb.update_cache()
return res
Expand All @@ -684,7 +705,7 @@ def pull(self, refspec=None, progress=None, **kwargs):
kwargs = add_progress(kwargs, self.repo.git, progress)
proc = self.repo.git.pull(self, refspec, with_stdout=False, as_process=True,
universal_newlines=True, v=True, **kwargs)
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
res = self._get_fetch_info_from_stderr(proc, progress)
if hasattr(self.repo.odb, 'update_cache'):
self.repo.odb.update_cache()
return res
Expand All @@ -694,10 +715,26 @@ def push(self, refspec=None, progress=None, **kwargs):

:param refspec: see 'fetch' method
:param progress:
Instance of type RemoteProgress allowing the caller to receive
progress information until the method returns.
If None, progress information will be discarded

No further progress information is returned after push returns.

A function (callable) that is called with the progress infomation:

progress( op_code, cur_count, max_count=None, message='' )

op_code is a bit mask of values defined in git.RemoteProgress
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of repeating the existing documentation in place, could you link to it ? It's fine to link to readthedocs, but certainly is possible to link to an API class locally as well. Unfortunately I don't know by heart how.

As you sometimes provide more information than is given in the existing one, you could consider manually merging it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather remove the RemoteProgress from public view. See comment in next section.


cur_count and max_count are float values.

max_count is None if there is no max_count

messages is '' if there is no additon message.

Deprecated: Pass in a class derived from git.RemoteProgres that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason to deprecate this - it should be fine to just remove Deprecated: here.

overrides the update() function.


:param kwargs: Additional arguments to be passed to git-push
:return:
IterableList(PushInfo, ...) iterable list of PushInfo instances, each
Expand All @@ -710,7 +747,7 @@ def push(self, refspec=None, progress=None, **kwargs):
kwargs = add_progress(kwargs, self.repo.git, progress)
proc = self.repo.git.push(self, refspec, porcelain=True, as_process=True,
universal_newlines=True, **kwargs)
return self._get_push_info(proc, progress or RemoteProgress())
return self._get_push_info(proc, progress)

@property
def config_reader(self):
Expand Down
5 changes: 4 additions & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
from git.config import GitConfigParser
from git.remote import (
Remote,
add_progress
add_progress,
progress_object
)

from git.db import GitCmdObjectDB
Expand Down Expand Up @@ -872,6 +873,8 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):

@classmethod
def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
progress = progress_object(progress)

# special handling for windows for path at which the clone should be
# created.
# tilde '~' will be expanded to the HOME no matter where the ~ occours. Hence
Expand Down
12 changes: 8 additions & 4 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,16 @@ class RemoteProgress(object):
DONE_TOKEN = 'done.'
TOKEN_SEPARATOR = ', '

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

def __init__(self):
def __init__(self, progress_function=None):
if progress_function is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the following 4 lines, does this work ?

self.__progress_function = progress_function if progress_function else self.update
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wish. I personal don't like that style.

self.__progress_function = progress_function
else:
self.__progress_function = self.update

self._seen_ops = list()
self._cur_line = None

Expand Down Expand Up @@ -267,7 +272,7 @@ def _parse_progress_line(self, line):
# END end message handling
message = message.strip(self.TOKEN_SEPARATOR)

self.update(op_code,
self.__progress_function(op_code,
cur_count and float(cur_count),
max_count and float(max_count),
message)
Expand Down Expand Up @@ -314,7 +319,6 @@ def update(self, op_code, cur_count, max_count=None, message=''):
You may read the contents of the current line in self._cur_line"""
pass


class Actor(object):

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