Skip to content

Commit af26d54

Browse files
authored
git: show progress during dulwich push/fetch (#5143)
1 parent 4b30b8b commit af26d54

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

dvc/scm/git/backend/dulwich.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Callable, Dict, Iterable, Optional, Tuple
88

99
from dvc.path_info import PathInfo
10+
from dvc.progress import Tqdm
1011
from dvc.scm.base import SCMError
1112
from dvc.utils import relpath
1213

@@ -54,6 +55,10 @@ def scandir(self) -> Iterable["DulwichObject"]:
5455
class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
5556
"""Dulwich Git backend."""
5657

58+
# Dulwich progress will return messages equivalent to git CLI,
59+
# our pbars should just display the messages as formatted by dulwich
60+
BAR_FMT_NOTOTAL = "{desc}{bar:b}|{postfix[info]} [{elapsed}]"
61+
5762
def __init__( # pylint:disable=W0231
5863
self, root_dir=os.curdir, search_parent_directories=True
5964
):
@@ -346,16 +351,23 @@ def update_refs(refs):
346351
new_refs[ref] = value
347352
return new_refs
348353

349-
def progress(msg):
350-
logger.trace("git send_pack: %s", msg)
351-
352354
try:
353-
client.send_pack(
354-
path,
355-
update_refs,
356-
self.repo.object_store.generate_pack_data,
357-
progress=progress,
358-
)
355+
with Tqdm(
356+
desc="Pushing git refs", bar_format=self.BAR_FMT_NOTOTAL
357+
) as pbar:
358+
359+
def progress(msg_b):
360+
msg = msg_b.decode("ascii").strip()
361+
pbar.update_msg(msg)
362+
pbar.refresh()
363+
logger.trace(msg)
364+
365+
client.send_pack(
366+
path,
367+
update_refs,
368+
self.repo.object_store.generate_pack_data,
369+
progress=progress,
370+
)
359371
except (NotGitRepository, SendPackError) as exc:
360372
raise SCMError("Git failed to push '{src}' to '{url}'") from exc
361373

@@ -417,12 +429,22 @@ def determine_wants(remote_refs):
417429
f"'{url}' is not a valid Git remote or URL"
418430
) from exc
419431

420-
def progress(msg):
421-
logger.trace("git fetch: %s", msg)
432+
with Tqdm(
433+
desc="Fetching git refs", bar_format=self.BAR_FMT_NOTOTAL
434+
) as pbar:
422435

423-
fetch_result = client.fetch(
424-
path, self.repo, progress=progress, determine_wants=determine_wants
425-
)
436+
def progress(msg_b):
437+
msg = msg_b.decode("ascii").strip()
438+
pbar.update_msg(msg)
439+
pbar.refresh()
440+
logger.trace(msg)
441+
442+
fetch_result = client.fetch(
443+
path,
444+
self.repo,
445+
progress=progress,
446+
determine_wants=determine_wants,
447+
)
426448
for (lh, rh, _) in fetch_refs:
427449
try:
428450
if rh in self.repo.refs:

0 commit comments

Comments
 (0)