From 8185c1731602205775077f811b8bed39f9d4322b Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 5 Apr 2020 15:38:04 +0100 Subject: [PATCH 1/4] scm: git: clone: add progress --- dvc/scm/git/__init__.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index e70d6f7b0f..ec1489673b 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -9,6 +9,7 @@ from pathspec.patterns import GitWildMatchPattern from dvc.exceptions import GitHookAlreadyExistsError +from dvc.progress import Tqdm from dvc.scm.base import Base from dvc.scm.base import CloneError, FileNotInRepoError, RevError, SCMError from dvc.scm.git.tree import GitTree @@ -18,6 +19,13 @@ logger = logging.getLogger(__name__) +class TqdmGit(Tqdm): + def update_git(self, op_code, cur_count, max_count=None, message=""): + if message: + self.set_description_str(message, refresh=False) + self.update_to(cur_count, max_count) + + class Git(Base): """Class for managing Git.""" @@ -72,12 +80,14 @@ def clone(url, to_path, rev=None): env[ld_key] = "" try: - tmp_repo = git.Repo.clone_from( - url, - to_path, - env=env, # needed before we can fix it in __init__ - no_single_branch=True, - ) + with TqdmGit(desc="Cloning") as pbar: + tmp_repo = git.Repo.clone_from( + url, + to_path, + env=env, # needed before we can fix it in __init__ + no_single_branch=True, + progress=pbar.update_git, + ) tmp_repo.close() except git.exc.GitCommandError as exc: raise CloneError(url, to_path) from exc From 8b66265393364db8d04066a2ab124ce989181fca Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 5 Apr 2020 23:49:49 +0100 Subject: [PATCH 2/4] git: add progress desc --- dvc/scm/git/__init__.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index ec1489673b..190fcec19c 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -21,10 +21,37 @@ class TqdmGit(Tqdm): def update_git(self, op_code, cur_count, max_count=None, message=""): + op_code = self.code2desc(op_code) + if op_code: + message = op_code + " " + message if message: self.set_description_str(message, refresh=False) self.update_to(cur_count, max_count) + @staticmethod + def code2desc(op_code): + from git import RootUpdateProgress as OP + + ops = dict( + ( + (OP.COUNTING, "Counting"), + (OP.COMPRESSING, "Compressing"), + (OP.WRITING, "Writing"), + (OP.RECEIVING, "Receiving"), + (OP.RESOLVING, "Resolving"), + (OP.FINDING_SOURCES, "Finding sources"), + (OP.CHECKING_OUT, "Checking out"), + (OP.CLONE, "Cloning"), + (OP.FETCH, "Fetching"), + (OP.UPDWKTREE, "Updating working tree"), + (OP.REMOVE, "Removing"), + (OP.PATHCHANGE, "Changing path"), + (OP.URLCHANGE, "Changing URL"), + (OP.BRANCHCHANGE, "Changing branch"), + ) + ) + return ops.get(op_code & OP.OP_MASK, "") + class Git(Base): """Class for managing Git.""" From 587d93c16e8bea315692be8c94acd9c9aeef9c71 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 9 Apr 2020 10:38:36 +0100 Subject: [PATCH 3/4] wip --- dvc/scm/git/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 190fcec19c..5f5bf13f97 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -107,7 +107,7 @@ def clone(url, to_path, rev=None): env[ld_key] = "" try: - with TqdmGit(desc="Cloning") as pbar: + with TqdmGit(desc="Cloning", unit="obj") as pbar: tmp_repo = git.Repo.clone_from( url, to_path, From 3844275531a2309d64ff4cb8c50dd20712932f4a Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 16 Apr 2020 21:51:13 +0100 Subject: [PATCH 4/4] git: tidy message --- dvc/scm/git/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 5f5bf13f97..6b5a3e2279 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -23,9 +23,9 @@ class TqdmGit(Tqdm): def update_git(self, op_code, cur_count, max_count=None, message=""): op_code = self.code2desc(op_code) if op_code: - message = op_code + " " + message + self.set_description_str(op_code, refresh=False) if message: - self.set_description_str(message, refresh=False) + self.set_postfix_str(message, refresh=False) self.update_to(cur_count, max_count) @staticmethod