Skip to content

Commit

Permalink
scm: git: clone: add progress (iterative#3595)
Browse files Browse the repository at this point in the history
* scm: git: clone: add progress

* git: add progress desc

* wip

* git: tidy message
  • Loading branch information
casperdcl authored Apr 17, 2020
1 parent 128fa7f commit f0c81bc
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +19,40 @@
logger = logging.getLogger(__name__)


class TqdmGit(Tqdm):
def update_git(self, op_code, cur_count, max_count=None, message=""):
op_code = self.code2desc(op_code)
if op_code:
self.set_description_str(op_code, refresh=False)
if message:
self.set_postfix_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."""

Expand Down Expand Up @@ -72,12 +107,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", unit="obj") 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
Expand Down

0 comments on commit f0c81bc

Please sign in to comment.