mirror of
https://github.com/Dev-Wiki/git-repo.git
synced 2025-09-26 10:02:46 +08:00
sync: Show elapsed time for the longest syncing project
"Last synced: X" is printed only after a project finishes syncing. Replace that with a message that shows the longest actively syncing project. Bug: https://crbug.com/gerrit/11293 Change-Id: I84c7873539d84999772cd554f426b44921521e85 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/372674 Reviewed-by: Josip Sokcevic <sokcevic@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com> Reviewed-by: Joanna Wang <jojwang@google.com> Tested-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -90,7 +90,7 @@ It is equivalent to "git branch -D <branchname>".
|
||||
success[branch].append(project)
|
||||
else:
|
||||
err[branch].append(project)
|
||||
pm.update()
|
||||
pm.update(msg="")
|
||||
|
||||
self.ExecuteInParallel(
|
||||
opt.jobs,
|
||||
|
@@ -58,7 +58,7 @@ The command is equivalent to:
|
||||
success.append(project)
|
||||
else:
|
||||
err.append(project)
|
||||
pm.update()
|
||||
pm.update(msg="")
|
||||
|
||||
self.ExecuteInParallel(
|
||||
opt.jobs,
|
||||
|
@@ -142,14 +142,14 @@ revision specified in the manifest.
|
||||
sync_buf = SyncBuffer(self.manifest.manifestProject.config)
|
||||
project.Sync_LocalHalf(sync_buf)
|
||||
project.revisionId = gitc_project.old_revision
|
||||
pm.update()
|
||||
pm.update(msg="")
|
||||
pm.end()
|
||||
|
||||
def _ProcessResults(_pool, pm, results):
|
||||
for result, project in results:
|
||||
if not result:
|
||||
err.append(project)
|
||||
pm.update()
|
||||
pm.update(msg="")
|
||||
|
||||
self.ExecuteInParallel(
|
||||
opt.jobs,
|
||||
|
@@ -66,7 +66,7 @@ from command import (
|
||||
from error import RepoChangedException, GitError
|
||||
import platform_utils
|
||||
from project import SyncBuffer
|
||||
from progress import Progress
|
||||
from progress import Progress, elapsed_str
|
||||
from repo_trace import Trace
|
||||
import ssh
|
||||
from wrapper import Wrapper
|
||||
@@ -596,7 +596,7 @@ later is required to fix a server side protocol bug.
|
||||
The projects we're given share the same underlying git object store, so
|
||||
we have to fetch them in serial.
|
||||
|
||||
Delegates most of the work to _FetchHelper.
|
||||
Delegates most of the work to _FetchOne.
|
||||
|
||||
Args:
|
||||
opt: Program options returned from optparse. See _Options().
|
||||
@@ -615,6 +615,8 @@ later is required to fix a server side protocol bug.
|
||||
Whether the fetch was successful.
|
||||
"""
|
||||
start = time.time()
|
||||
k = f"{project.name} @ {project.relpath}"
|
||||
self._sync_dict[k] = start
|
||||
success = False
|
||||
remote_fetched = False
|
||||
buf = io.StringIO()
|
||||
@@ -660,15 +662,31 @@ later is required to fix a server side protocol bug.
|
||||
% (project.name, type(e).__name__, str(e)),
|
||||
file=sys.stderr,
|
||||
)
|
||||
del self._sync_dict[k]
|
||||
raise
|
||||
|
||||
finish = time.time()
|
||||
del self._sync_dict[k]
|
||||
return _FetchOneResult(success, project, start, finish, remote_fetched)
|
||||
|
||||
@classmethod
|
||||
def _FetchInitChild(cls, ssh_proxy):
|
||||
cls.ssh_proxy = ssh_proxy
|
||||
|
||||
def _GetLongestSyncMessage(self):
|
||||
if len(self._sync_dict) == 0:
|
||||
return None
|
||||
|
||||
earliest_time = float("inf")
|
||||
earliest_proj = None
|
||||
for project, t in self._sync_dict.items():
|
||||
if t < earliest_time:
|
||||
earliest_time = t
|
||||
earliest_proj = project
|
||||
|
||||
elapsed = time.time() - earliest_time
|
||||
return f"{elapsed_str(elapsed)} {earliest_proj}"
|
||||
|
||||
def _Fetch(self, projects, opt, err_event, ssh_proxy):
|
||||
ret = True
|
||||
|
||||
@@ -681,8 +699,22 @@ later is required to fix a server side protocol bug.
|
||||
delay=False,
|
||||
quiet=opt.quiet,
|
||||
show_elapsed=True,
|
||||
elide=True,
|
||||
)
|
||||
|
||||
self._sync_dict = multiprocessing.Manager().dict()
|
||||
sync_event = _threading.Event()
|
||||
|
||||
def _MonitorSyncLoop():
|
||||
while True:
|
||||
pm.update(inc=0, msg=self._GetLongestSyncMessage())
|
||||
if sync_event.wait(timeout=1):
|
||||
return
|
||||
|
||||
sync_progress_thread = _threading.Thread(target=_MonitorSyncLoop)
|
||||
sync_progress_thread.daemon = True
|
||||
sync_progress_thread.start()
|
||||
|
||||
objdir_project_map = dict()
|
||||
for project in projects:
|
||||
objdir_project_map.setdefault(project.objdir, []).append(project)
|
||||
@@ -712,7 +744,7 @@ later is required to fix a server side protocol bug.
|
||||
ret = False
|
||||
else:
|
||||
fetched.add(project.gitdir)
|
||||
pm.update(msg=f"Last synced: {project.name}")
|
||||
pm.update()
|
||||
if not ret and opt.fail_fast:
|
||||
break
|
||||
return ret
|
||||
@@ -764,6 +796,7 @@ later is required to fix a server side protocol bug.
|
||||
# crash.
|
||||
del Sync.ssh_proxy
|
||||
|
||||
sync_event.set()
|
||||
pm.end()
|
||||
self._fetch_times.Save()
|
||||
|
||||
|
Reference in New Issue
Block a user