From 863b386e195bb2b609b25614f732b1b502bc79a4 Mon Sep 17 00:00:00 2001 From: jez Date: Sat, 21 May 2011 10:13:45 +0000 Subject: Add progress tracking for git-clone. --- git/repo/base.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 0405a5f9..55aec05b 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -18,6 +18,11 @@ from git.db import ( ) +from git.util import ( + _digest_process_messages, + _finalize_proc + ) + from gitdb.util import ( join, isfile, @@ -652,7 +657,7 @@ class Repo(object): return Repo(path) @classmethod - def _clone(cls, git, url, path, odb_default_type, **kwargs): + def _clone(cls, git, url, path, odb_default_type, progress, **kwargs): # 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 @@ -679,7 +684,10 @@ class Repo(object): # END windows handling try: - git.clone(url, path, **kwargs) + proc = git.clone(url, path, with_extended_output=True, as_process=True, v=True, progress=True, **kwargs) + if progress: + _digest_process_messages(proc.stderr, progress) + _finalize_proc(proc) finally: if prev_cwd is not None: os.chdir(prev_cwd) @@ -703,11 +711,13 @@ class Repo(object): # END handle remote repo return repo - def clone(self, path, **kwargs): + def clone(self, path, progress=None, **kwargs): """Create a clone from this repository. :param path: is the full path of the new repo (traditionally ends with ./.git). + :param progress: See 'git.remote.Remote.push'. + :param kwargs: odbt = ObjectDatabase Type, allowing to determine the object database implementation used by the returned Repo instance @@ -715,16 +725,17 @@ class Repo(object): All remaining keyword arguments are given to the git-clone command :return: ``git.Repo`` (the newly cloned repo)""" - return self._clone(self.git, self.git_dir, path, type(self.odb), **kwargs) + return self._clone(self.git, self.git_dir, path, type(self.odb), progress, **kwargs) @classmethod - def clone_from(cls, url, to_path, **kwargs): + def clone_from(cls, url, to_path, progress=None, **kwargs): """Create a clone from the given URL :param url: valid git url, see http://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS :param to_path: Path to which the repository should be cloned to + :param progress: See 'git.remote.Remote.push'. :param kwargs: see the ``clone`` method :return: Repo instance pointing to the cloned directory""" - return cls._clone(Git(os.getcwd()), url, to_path, GitCmdObjectDB, **kwargs) + return cls._clone(Git(os.getcwd()), url, to_path, GitCmdObjectDB, progress, **kwargs) def archive(self, ostream, treeish=None, prefix=None, **kwargs): """Archive the tree at the given revision. -- cgit v1.2.1 From 55eb3de3c31fd5d5ad35a8452060ee3be99a2d99 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 7 Jun 2011 21:25:38 +0200 Subject: Added conditional usage of the --progress flag to all relevant methods, that is push, fetch, pull and clone. This allows progress information to be sent in newer git versions without breaking older ones (ideally) --- git/repo/base.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 55aec05b..14efabdc 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -11,18 +11,18 @@ from git.refs import * from git.index import IndexFile from git.objects import * from git.config import GitConfigParser -from git.remote import Remote +from git.remote import ( + Remote, + digest_process_messages, + finalize_process, + add_progress + ) + from git.db import ( GitCmdObjectDB, GitDB ) - -from git.util import ( - _digest_process_messages, - _finalize_proc - ) - from gitdb.util import ( join, isfile, @@ -684,10 +684,11 @@ class Repo(object): # END windows handling try: - proc = git.clone(url, path, with_extended_output=True, as_process=True, v=True, progress=True, **kwargs) + proc = git.clone(url, path, with_extended_output=True, as_process=True, v=True, **add_progress(kwargs, git, progress)) if progress: - _digest_process_messages(proc.stderr, progress) - _finalize_proc(proc) + digest_process_messages(proc.stderr, progress) + #END handle progress + finalize_process(proc) finally: if prev_cwd is not None: os.chdir(prev_cwd) -- cgit v1.2.1